swapActiveAndBackgroundStores method

void swapActiveAndBackgroundStores({
  1. required AFMergePublicStateDelegate mergePublicState,
})

Implementation

void swapActiveAndBackgroundStores({
  required AFMergePublicStateDelegate mergePublicState,
}) {
  // we need to actually swap public background state into the original state
  final stateUI = uiStore!.store!.state;
  final stateBackground = backgroundStore!.store!.state;
  final revisedPublic = mergePublicState(stateUI.public, stateBackground.public);

  final revisedUI = stateUI.revisePublic(revisedPublic);

  // now, the UI state becomes the background state with the merged public data.
  uiStore!.store!.dispatch(AFUpdateRootStateAction(revisedUI));

  // and the background state becomes the former UI state.
  backgroundStore!.store!.dispatch(AFUpdateRootStateAction(stateUI));
}