PersistedNode<T> class
A specialized ZenithNode that automatically restores state from a ZenithStorage backend on creation and saves updates on mutation.
final themeNode = PersistedNode.string(
key: 'app.theme',
defaultValue: 'system',
storage: localStorage,
);
print(themeNode.value); // Restored from storage, or 'system'
themeNode.set('dark'); // Mutates node & asynchronously writes to storage
- Inheritance
-
- Object
- ZenithNode<
T> - PersistedNode
- Available extensions
Constructors
- PersistedNode({required String key, required T defaultValue, required ZenithStorage storage, required String toStorage(T value), required T fromStorage(String raw)})
- Creates a PersistedNode with custom serialization callbacks.
Properties
- debugSubscriberCount → int
-
The current number of subscribers (including potentially dead weak
references that have not yet been pruned).
no setterinherited
- fromStorage → T Function(String raw)
-
Deserializer callback parsing String back into
T.final - hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether this node has been disposed.
no setterinherited
- key → String
-
The key used for storage lookup.
final
- persistenceError → Object?
-
Latest write/serialization failure, cleared after a successful write.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storage → ZenithStorage
-
The storage backend powering this node.
final
- toStorage → String Function(T value)
-
Serializer callback converting
Tto a String.final - value ↔ T
-
The current value held by this node.
getter/setter pairinherited
Methods
-
dispose(
{bool purgeZeroize = false}) → void -
Permanently disposes this node, clearing all subscribers.
inherited
-
flush(
) → Future< void> - Awaits this node's latest accepted write and propagates its failure. Call before ending a scope when durability is required.
-
guard(
ZenithRef ref, Future< T> future()) → Future<void> -
Available on ZenithNode<
ExecutesAsyncValue< , provided by the SafeAsyncNodeX extensionT> >futureand writes its result to this node, guarding every mutation withref's lifecycle. Equivalent toref.runAsync(this, future). -
invalidate(
) → void -
Forces a notification pass without changing the value.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifySubscribers(
) → void -
Notifies all live subscribers that this node has changed.
inherited
-
set(
T newValue) → void -
Sets the value of this node and notifies all active subscribers.
override
-
subscribe(
ZenithSubscriber subscriber) → ZenithSubscription -
Adds
subscriberto this node's listener set.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
trySet(
T newValue) → bool -
Attempts to update the value of this node.
inherited
-
unsubscribe(
ZenithSubscriber subscriber) → void -
Removes
subscriberfrom this node's listener set.inherited -
watch(
ZenithRef ref, Stream< T> stream) → StreamSubscription<T> -
Available on ZenithNode<
Subscribes toAsyncValue< , provided by the StreamNodeX extensionT> >streamand writes each event to this node, guarding every mutation withref's lifecycle.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
boolean(
{required String key, required bool defaultValue, required ZenithStorage storage}) → PersistedNode< bool> - Helper for boolean persisted nodes.
-
integer(
{required String key, required int defaultValue, required ZenithStorage storage}) → PersistedNode< int> - Helper for integer persisted nodes.
-
string(
{required String key, required String defaultValue, required ZenithStorage storage}) → PersistedNode< String> - Helper for string persisted nodes.