ValueStore<T> class
A value store is a tree structure that takes a path and indexes its value into the tree as a key of its parent path, enabling efficient access to all values of the parent path.
Ex. In this example, the parent path users__2__messages
indexes the value 'Test' by its key 1
.
final store = ValueStore<String>();
store.write('users__2__messages__1', 'Test');
store.write('users__2__messages__2', 'Test again');
print(store.inspect());
{
users: {
2: {
messages: {
__values: {
1: 'Test',
2: 'Test again',
}
}
}
}
}
All values of the given path can then be retrieved as shown below:
final values = store.getChildValues('users__2__messages');
print(values);
{
1: 'Test',
2: 'Test again',
}
The ValueStore is the data structure used throughout the library for storing collections of documents.
- Implementers
Constructors
- ValueStore({Map? store})
Properties
Methods
-
clear(
) → void -
delete(
String path, {bool recursive = true}) → void - Deletes the values at the given path and optionally its subtree from the store.
-
extractValues(
[String path = '']) → Map< String, T> - Extracts all values under the given path in the store into a set of flat key-value pairs of paths to values.
-
findValue(
String path, dynamic value) → String? - Returns the first subpath along the given path that has a value equal to the provided value (if any).
-
get(
String path) → T? - Returns the value for the given path.
-
getChildValues(
String path) → Map< String, T> ? - Returns a map of all values that are immediate children of the given path.
-
getNearest(
String path) → T? - Returns the nearest value along the given path, beginning at the full path and then attempting to find a non-null value for any parent node moving up the tree.
-
graft(
ValueStore< T> other, [String path = '']) → void -
Removes the subtree at the given
path
of the other provided ValueStore and recursively merges it onto this store at the given path. -
hasChildValues(
String path) → bool - Returns whether the store has any child values under the given path.
-
hasPath(
String path) → bool - Returns whether the store contains the given path either as a value or a path to subtree values.
-
hasValue(
String path) → bool - Returns whether the store has a value for the given path.
-
inspect(
) → Map - Returns a map of the values in the store by path.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
touch(
String path) → Map -
write(
String path, T value) → T - Writes the value at the given path.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromJson(
Json json) → ValueStore< Json>