Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: createOffline persist docs #229

Merged
merged 2 commits into from May 18, 2018

Conversation

Projects
None yet
3 participants
@sorodrigo
Copy link
Member

commented May 17, 2018

The redux-offline peeks the offlineAction to process everytime an action goes through the middleware chain. This works fine for actions dispatched in the same session. However when the store gets rehydrated if there's actions on the outbox, these will remain there until an action is dispatched. This is because, the offline middleware is registered after the persist has been configured so the PERSIST_REHYDRATE action doesn't trigger the offline process.

The solution is to simply apply middleware before enhancing the store.

More info forest-watcher/forest-watcher#303

sorodrigo added some commits May 17, 2018

@sorodrigo sorodrigo requested a review from wacii May 17, 2018

@wacii

wacii approved these changes May 17, 2018

Copy link
Collaborator

left a comment

Nifty. I'm so used to doing it middleware then enhancer that I don't even think about it anymore. Guess I shouldn't do that.

I tested the change with vanilla apps, but I didn't try it with redux-saga.

@sorodrigo

This comment has been minimized.

Copy link
Member Author

commented May 18, 2018

Already tested in a saga application on my side, so merging. ✌️

@sorodrigo sorodrigo merged commit aead259 into develop May 18, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@sorodrigo sorodrigo deleted the fix-create-offline-persist-docs branch May 18, 2018

sorodrigo added a commit that referenced this pull request Jun 30, 2018

Fix: middleware can't listen to persist/REHYDRATE (#229)
* apply persist fix to sagas example

sorodrigo added a commit that referenced this pull request Jun 30, 2018

Merge branch 'develop'
* develop: (33 commits)
  fixes flow -> update queue context to include outbox
  Updating typescript typings to match current js types
  Fix missing Offline/Busy action
  Queue methods with additional context parameter (#217)
  Fix: middleware can't listen to persist/REHYDRATE (#229)
  Update createOffline's middleware typings
  feat: add sagas config docs (#215)
  2.3.3
  fix: add missing flow types
  fix: no promises example
  Readd queue example
  Misc changes to new docs
  Fix typos in next example
  Fix correct line in decorate actions
  Fix decorate actions section of quickstart
  Fix decorate actions section of quick start
  Update getting started
  Add executable axios code example
  Fix Table of Contents links
  Shorten the main README
  ...
@MartinJHammer

This comment has been minimized.

Copy link

commented Oct 22, 2018

Adding my fix example here as well (first added in forest-watcher/forest-watcher#303)

The change fixing the problem happens in composeEnhancers()

My store creation before (actions not firing before other action is fired):

const store: Store<IAppState> = createStore(
        offlineEnhancer.enhanceReducer(rootReducer),
        initialState,
        composeEnhancers(
            applyMiddleware(offlineEnhancer.middleware as any, epicMiddleware),
            offlineEnhancer.enhanceStore,
        )
    );

My store create after (offline queue now immediatly dispatches)

   const store: Store<IAppState> = createStore(
        offlineEnhancer.enhanceReducer(rootReducer),
        initialState,
        composeEnhancers(
            offlineEnhancer.enhanceStore,
            applyMiddleware(offlineEnhancer.middleware as any, epicMiddleware),
        )
    );

@MartinJHammer MartinJHammer referenced this pull request Oct 23, 2018

Closed

Troubleshooting #278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.