call method

void call(
  1. SnapState<T> snap,
  2. InjectedImp<T> injected
)

Implementation

void call(SnapState<T> snap, InjectedImp<T> injected) async {
  _addToUndoQueue(snap);
  if (persistanceProvider == null) {
    return;
  }
  if (persistanceProvider!.persistOn == null) {
    final oldSnap = injected._snapState.oldSnapState;
    try {
      if (snap.data == null) {
        return await persistanceProvider!.delete();
      }
      await persistanceProvider!.write(snap.data as T);
    } catch (e, s) {
      if (persistanceProvider!.catchPersistError) {
        StatesRebuilerLogger.log('Write to localStorage error', e, s);
        return null;
      }

      injected
        .._snapState = oldSnap!
        ..setToHasError(
          e,
          stackTrace: s,
          refresher: () {},
        );
    }
  }
}