redurx_persist 0.9.0 copy "redurx_persist: ^0.9.0" to clipboard
redurx_persist: ^0.9.0 copied to clipboard

discontinued

Persist ReduRx State with custom storage engines and serializers

example/redurx_persist_example.dart

import 'dart:io';

import 'package:redurx/redurx.dart';
import 'package:redurx_persist/redurx_persist.dart';

void main() async {
  final persistor = Persistor<State>(
    storage: FileStorage(File("state.json")),
    serializer: JsonSerializer<State>(State.fromJson),
  );

  // Load initial state
  final initialState = await persistor.load();

  final store = Store<State>(initialState ?? State(counter: 0));

  // ...
}

class State {
  final int counter;

  State({this.counter = 0});

  State copyWith({int counter}) => State(counter: counter ?? this.counter);

  static State fromJson(dynamic json) => State(counter: json["counter"] as int);

  dynamic toJson() => {'counter': counter};
}

class IncrementCounter extends Action<State> {
  @override
  State reduce(State state) => state.copyWith(counter: state.counter + 1);
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

Persist ReduRx State with custom storage engines and serializers

Homepage
Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

meta, redurx, synchronized

More

Packages that depend on redurx_persist