redux_persist_web 0.8.2

redux_persist_web pub package

Web Storage Engine for redux_persist.

Saves to localStorage.

Usage #

final persistor = Persistor<AppState>(
  // ...
  storage: WebStorage(),
);

Key #

You can pass a key argument to WebStorage to set the key for localStorage.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.8.2 - 2019-03-03

  • Republishing to fix score (published before redux_persist update)

0.8.1 - 2019-03-03

  • Add example.

0.8.0 - 2018-11-27

  • Release v0.8.0. Last v0.x release line.

0.8.0-rc.0 - 2018-11-06

  • Update to newest redux_persist (make match versions).

0.4.2 - 2018-03-14

  • Fix library export.

0.4.1 - 2018-03-10

  • Fix Future returning.

0.4.0 - 2018-03-10

  • Initial decoupling.

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;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  redux_persist_web: ^0.8.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:redux_persist_web/redux_persist_web.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
52
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: web

Primary library: package:redux_persist_web/redux_persist_web.dart with components: html, io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <3.0.0
redux_persist ^0.8.2 0.8.2
Transitive dependencies
meta 1.1.7
redux 3.0.0
synchronized 2.1.0+1