-
Notifications
You must be signed in to change notification settings - Fork 679
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
Why records property is not updating with fetch? #177
Comments
So if I'm understanding it correctly, every time you run |
I'm removing the |
I have the same problem. |
Hi @chris136 - is the local storage being updated in multiple places? e.g. are there two models referencing the local storage record? |
No, just one model. I use it to save calendar events created via drag and drop. I noticed newly created events were missing when I switched a week back and forth. But after a complete site reload, the events were back where they were created. |
Thanks for the information @chris136 If I understand this correctly, what's happening is:
Basically, once there's a list of records in the collection, I can have a look at this over the weekend and try to re-create the issue in a test environment. |
I'm not able to test the reaction to the storage event as it only fires on the window that's _not_ doing the `setItem` call.
Hi @chris136 Would it be possible for you to check the version of Backbone.localStorage that you're using? I've been trying to recreate this in tests and the output seems to be acting the way I'd expect in version 2.0.0. |
@scott-w according to the changelog I use version 1.1.16 (January 22, 2015). |
Thanks @chris136, is the issue still present? |
@scott-w yes, that is the version where I noticed the problem. |
I try to make a minimal test case if I find the time this week. |
HI @chris136 That'll be awesome, thanks 👍 |
Any updates on this issue? or is there any workaround? Cheers! |
I fixed this in my backbone fork. Look at the following commits: Should not be hard to make a PR. Currently i'm on a slow internet connection so cannot do it myself |
I use localStorage collection, works great. But I want use storage event for updating collection in many tabs. Idea: do fetch() when storage event fires.
But this shouldn't work as expetcted because records property will not be updated with fetch and save() method use records prop. And so all actual data which came from one tab will be rewrited by old data from another tab.
So I rewrited code in this way:
And it works great.
Suggested solution: I think that we can put this code to the another method in the localStorage object (records_update) and call this method from constructor and from Backbone.sync() when doing fetch() or from findAll() before getting particular model. I think this property must be updated on fetch, not only at the collection initialization time.
The text was updated successfully, but these errors were encountered: