JsonPersistenceMiddleware<T> class

Convenience middleware for persisting reactons with JSON serialization.

final settingsReacton = reacton(
  Settings.defaults(),
  options: ReactonOptions(
    middleware: [
      JsonPersistenceMiddleware(
        storage: memoryStorage,
        key: 'settings',
        toJson: (s) => s.toJson(),
        fromJson: (j) => Settings.fromJson(j),
      ),
    ],
  ),
);
Inheritance

Constructors

JsonPersistenceMiddleware({required StorageAdapter storage, required String key, required Map<String, dynamic> toJson(T), required T fromJson(Map<String, dynamic>)})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onAfterWrite(ReactonBase<T> reacton, T value) → void
Called after a value has been written and propagated.
inherited
onBeforeWrite(ReactonBase<T> reacton, T currentValue, T newValue) → T
Called before a value is written to the reacton. Return the (possibly modified) value, or throw to reject the write.
inherited
onDispose(ReactonBase<T> reacton) → void
Called when the reacton is disposed from the store.
inherited
onError(ReactonBase<T> reacton, Object error, StackTrace stackTrace) → void
Called when an error occurs during computation.
inherited
onInit(ReactonBase<T> reacton, T initialValue) → T
Called when the reacton is first initialized. Return the initial value (possibly modified).
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited