redux_persist_web 0.8.1 copy "redux_persist_web: ^0.8.1" to clipboard
redux_persist_web: ^0.8.1 copied to clipboard

outdated

Redux Persist Web Integration with custom storage engines (localStorage)

example/redux_persist_web_example.dart

import 'package:redux/redux.dart';
import 'package:redux_persist/redux_persist.dart';
import 'package:redux_persist_web/redux_persist_web.dart';

void main() async {
  // Create Persistor
  final persistor = Persistor<AppState>(
    storage: WebStorage(),
    serializer: JsonSerializer<AppState>(AppState.fromJson),
  );

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

  final store = Store<AppState>(
    reducer,
    initialState: initialState ?? AppState(),
    middleware: [persistor.createMiddleware()],
  );

  // ...
}

// Redux
class AppState {
  final int counter;

  AppState({this.counter = 0});

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

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

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

class IncrementCounterAction {}

AppState reducer(AppState state, Object action) {
  if (action is IncrementCounterAction) {
    // Increment
    return state.copyWith(counter: state.counter + 1);
  }

  return state;
}
0
likes
40
pub points
29%
popularity

Publisher

verified publishercretezy.com

Redux Persist Web Integration with custom storage engines (localStorage)

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

redux_persist

More

Packages that depend on redux_persist_web