-
Notifications
You must be signed in to change notification settings - Fork 108
Option for performing local sync first #65
Comments
I think what you're doing is a good idea. You should be able to pull this off by setting your collection/model to be local, except when you call
It seems like
Could you test it out and make sure it works for you? Since you brought this up, I also just updated the README to document that you can use a function for the local/remote options. Thanks! |
Thanks for your quick response! I'm now playing with the offline collections, and still learning how it works. One idea: dualStorage was working for me always online, trying connections all the time, but enquing for later the failed connections. That's a killer approach. What I imagine could even be better (I rephrase to make sure we are on the same page) is that dualStorage continues to think it's always online, but every connection is async. So, if I add an item to a collection, it instantly adds it, updates localStorage, and tries a connection or enqueues. Fetch the index page? No problem! Grab the collection from localStorage, and check if the API is available to grab fresh data. Much like HTML5 manifest: where it loads everything as if offline, and any change to be seen takes another request. Is your approach of taking the models offline ( Thank you very much for your time. |
Yes, exactly. Probably the reason it was implemented this way (default to It may be worth thinking about making this the default behavior in the future for the next major release (2.0). Specifically:
If you're interested in having Backbone.dualStorage manage that, I think that would be great. Feel free to discuss with me how you think it should behave, and maybe you can start a new branch to begin work on it. Let me know what you think. Also please let me know if my change in master allows |
In the app this was built for initially, the local source was the authoritative one, so a single callback was preferable. There could be a callback passed to |
@tute I'm sorry, it seems that I remembered wrong about setting I could change that line to allow you to pass the
That's really not ideal, but it would work as a workaround for now. Alternatively, you could set local dynamically only when fetching, but not when saving/destroying. That would get you instant loads from cache and slow/online write operations. Something like:
What do you think? |
Hi, thank you both for your great feedback. Following two ideas sound so good to me:
I was actually wanting so much to have callbacks for both offline and online updates, right now. Having the feedback (for the developer or end users as well) that something is only on your device until you get a better connection or manually sync seems like very healthy to me, right now writing app code that works around it inspecting That's another topic, regarding the local-first behavior I'm still not testing (have to install some software to throttle my connection, will get back to you on it). The idea for Till next, thank you again very much! |
Here's a different flow for a similar problem (I'm sure you already know it, in my to-do list to test and compare): https://github.com/ggozad/Backbone.cachingSync#behavior |
I actually was not aware of Backbone.cachingSync. Thank you for bringing it to my attention. I'll have to take a look and see what they're doing too. I will definitely consider your desired sync behavior for a future release. You have a very compelling use case. Feel free to start on something before I do, if you decide to stick with dualStorage. |
This was ineffective for its purpose and caused local/remote to be ignored at uninteded times, as in #62, #70. Revert 25b890f "syncDirty disregards local/remote options too". Revert 48fb695 "syncDirtyAndDestroyed is not affected by local/remote options" Conflicts: backbone.dualstorage.amd.js backbone.dualstorage.coffee backbone.dualstorage.js spec/backbone.dualstorage.js
Just a heads up: I just changed Keep in touch! |
I don't understand why do we need |
Awesome, I'm glad that worked for you. You didn't misunderstand - I got it backward. Whoops! Edited my original comment. :-) |
Cool. And my slow action was fetch, all the others are correctly handled (syncing the views instantly, performing the API call for as long as it takes), so I'm really happy with the solution. For the record, it ended up as: localFirstFetch: (options = {}) ->
@fetch(options)
setTimeout (=>
@localFetching = true
@fetch(options)
@localFetching = false
), 1
local: ->
@localFetching As I write this I see that I could just change |
Yes, that would work too and perhaps be a little simpler. |
Indeed this is all, getting elegant! :) localFirstFetch: (options = {}) ->
@fetch(options)
setTimeout (=>
@local = true
@fetch(options)
@local = false
), 1 Checking it with a connection throttler and looking good. Will now try with no timeout. |
So with no timeout somehow it doesn't render, that's the best I could come up with. Should we integrate it into the library? |
Are you saying the page doesn't render because of a javascript error? |
Oh no, it's like if an event is not fired, or something. There has to be a race condition or something, I could spend more time figuring it out why do we need that delay (kind of like a |
ah, I see. I'll have to look into this more later. |
I do have an |
I think I might have this sorted. See pull request #86 |
I don't know if it works exactly the same, we should compare each other's solution. :) To throttle the connection in my Mac I use http://slowyapp.com/. |
I have slowy app too. Not sure if it throttles local host though... |
I'm finding this project really useful, thank you very much for it!
I'm building a mobile app for places with low connectivity. One issue I find is that it's better to get completely offline than on slow EDGE/3G connections, cause when it knows it's online it will wait even for the slowest queries. I'd like to be able to tell dualStorage to infer offline, and perform sync in the background, or manually when I tell it to.
Is there any way we can do so right now? If not, I'm happy to receive general guidance and try it in a fork!
Possibly related: #4
Thank you very much in advance.
The text was updated successfully, but these errors were encountered: