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

Synchronization? #54

Open
aij opened this issue Aug 30, 2016 · 6 comments
Open

Synchronization? #54

aij opened this issue Aug 30, 2016 · 6 comments

Comments

@aij
Copy link

aij commented Aug 30, 2016

I was wondering how this library handles synchronization. It would appear the answer is that it doesn't, but please correct me if I'm wrong. (In which case, documentation would be nice. :) )

For example, with two tabs using localStorage, each tab will read from localStorage when the middleware is initialized, after which point they will blindly write over each other's writes. (So, whichever tab writes last wins, and the data is not synchronized to the other tab until the app is reloaded.)

@vicentedealencar
Copy link

I don't think the changes feed is been listened to.

You should checkout redux-pouchdb, it is simpler than this but may suits your needs.

@NeXTs
Copy link

NeXTs commented Sep 28, 2016

This advice causes to install and depend on whole pouchDB library

@aij did you found satisfying solution?

@elgerlambert
Copy link
Owner

HI @aij,

You're right; the behaviour you describe is indeed what I would expect to happen.

I hadn't considered this use case/scenario before, my first reaction would be to write a piece of middleware that listens to the 'storage' event and dispatch those changes to update the store state of the other tab(s). Your reducer(s) would consequently determine how to merge these changes.

Is this something you considered? Are there issues you run into with this approach?

@kostia1st
Copy link

I think this improvement should be considered essential for the library. Otherwise, it's limited to a very few use cases, and you basically cannot use it for storing auth tokens for instance.

@aij
Copy link
Author

aij commented May 19, 2017

FWIW, I ended up using redux-persist with redux-persist-crosstab, and handling the the REHYDRATE action explicitly to merge the changes in my reducer. I also had to work around an infinite loop in IE.

@kostia1st
Copy link

@aij thanks, that helped. We just implemented the same approach, exactly what we needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants