Kvoti / redux-rest

Automatically create Redux action constants, action creators, and reducers for your REST API
MIT License
180 stars 11 forks source link

Duplicate _pendingID issue #14

Open bhoomit opened 8 years ago

bhoomit commented 8 years ago

I'm using redux-localstorage to retain store state between page refreshes. In which case ActionCreators will get "reinitialize" and the default _pendingID will reset to 0. Because of this I have duplicate pending ids in the redux store and it causes the issue in getting the latest state from the store.

I have a quick fix for this. But I want to get your opinion on this issue.

mallison commented 8 years ago

What's your idea?

At a quick glance I was thinking we could put that id in the store as action creators can call getState then the pending action reducer can increment it. Not completely sure that'd work.

bhoomit commented 8 years ago

Let me think about your idea. My idea is basically set the default pending Id to current timestamp. That would make sure it's never a duplicate. On May 21, 2016 15:27, "Mark Allison" notifications@github.com wrote:

What's your idea?

At a quick glance I was thinking we could put that id in the store as action creators can call getState then the pending action reducer can increment it. Not completely sure that'd work.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/Kvoti/redux-rest/issues/14#issuecomment-220769341

mallison commented 8 years ago

That would work too.

I wonder if it'd be better to be able to specify a field that's unique for each endpoint. That way you could match up the ajax response to the pending item without the need for the _pendingID. It'd also let you do more advanced things like check if there's already a request in-flight for/with the same data. For a GET on a collection endpoint you don't need an ID as you'd only ever want one such request active.

On 21 May 2016 at 11:34, Bhoomit notifications@github.com wrote:

Let me think about your idea. My idea is basically set the default pending Id to current timestamp. That would make sure it's never a duplicate. On May 21, 2016 15:27, "Mark Allison" notifications@github.com wrote:

What's your idea?

At a quick glance I was thinking we could put that id in the store as action creators can call getState then the pending action reducer can increment it. Not completely sure that'd work.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/Kvoti/redux-rest/issues/14#issuecomment-220769341

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/Kvoti/redux-rest/issues/14#issuecomment-220770731

bhoomit commented 8 years ago

Yes, I think that would be a better implementation.