Cretezy / redux_persist

Persist Redux State
https://pub.dartlang.org/packages/redux_persist
MIT License
130 stars 41 forks source link

Multiple Action Dispatch #23

Closed vishant-jaiswal closed 6 years ago

vishant-jaiswal commented 6 years ago

with every restart i see multiple call for save and done as below

I/flutter (23114): Persistor debug: Starting loading I/flutter (23114): Persistor debug: Done loading I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): YardAnimation Completed I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Start saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving I/flutter (23114): Persistor debug: Done saving

will this hamper the performance and i m worried what will happen as the store grows?

Cretezy commented 6 years ago

It seems like you a dispatching many many actions.

I would recommend creating one action that does many changes inside the reducer.

Cretezy commented 6 years ago

This was fixed in 0.8.0-rc.0, let me know if that fixes your problem!

vishant-jaiswal commented 6 years ago

Thanks...will do the testing again and let you know

vishant-jaiswal commented 6 years ago

Hey Cretezy,

It seems the implementation itself changed a lot now we dont need to pass store variable to persistor.load().

I changed my code as you mentioned in example. Now i am getting following error while application launch.

Installing build\app\outputs\apk\app.apk...                 10.7s
E/flutter (28612): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (28612): SerializationException: On load: NoSuchMethodError: The getter 'length' was called on null.
E/flutter (28612): Receiver: null
E/flutter (28612): Tried calling: length
E/flutter (28612): #0      Persistor.load (package:redux_persist/src/persistor.dart:131:7)
E/flutter (28612): <asynchronous suspension>

i tried with 0.8.0-rc.0 as well as 0.8.0-rc.1

this is my implementaion of main fucnction

void main() async {
  // Create Persistor

  final persistor = Persistor<AppState>(
    storage: FlutterStorage(),
    serializer: JsonSerializer<AppState>(AppState.fromJson),
  );

  // Load initial state

  final initialState = await persistor.load();

  Store store = Store<AppState>(
    appReducer,
    initialState: initialState ?? AppState(),
    middleware: []
      ..addAll(createAuthMiddleware())
      //..add(LoggingMiddleware.printer())
      ..add(persistor.createMiddleware()),
  );

  runApp(new MyApp());
}

tell me if i am doing anything wrong here

Cretezy commented 6 years ago

It is possible that your AppState.fromJson does a .length on a null value?

The decoder must be able to accept a null value passed in. Usually you'll want to return an empty state when this happens.