-
Notifications
You must be signed in to change notification settings - Fork 140
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
As an app developer I want to know when syncing is done #732
Comments
Fixed by #698 - listen for: remoteStorage.local.on('local-events-done', function() {
console.log('all local events have been fired now');
}); |
Nice! Why is this part of |
There's no way to know when "syncing is done", which is why the event is now called "wire-done" instead of "sync-done". The local-events-done just means that during startup all local change events for the data that is already stored have been fired. |
True, does not what I am looking for. |
Right, I see what you mean. There is no explicit event for "sync done at least once", only for "this sync cycle has completed successfully". It's the 'done' event on remoteStorage.local.on('local-events-done', function() {
var syncDoneOnce = false;
console.log('all local events have been fired; waiting for initial sync to finish now');
remoteStorage.sync.on('done', function() {
if (!syncDoneOnce) {
syncDoneOnce = true;
console.log('now you can safely render your view the first time');
renderTheView();
console.log('from now on, will re-render the view after each incoming change');
remoteStorage.on('change', renderTheView);
}
});
}); |
Actually we should add this to some sort of FAQ. Reopening this with a 'docs' label. |
Hacking it this way doesn't make any sense in my opinion. It's the whole reason why we only fulfill the promise of @xMartin You can now safely use |
right, that would be an alternative. Put the var changeHandlerRegistered = false;
function renderTheView() {
remoteStorage.stuff.getAllStuff().then(function(allStuff) {
updateHtml(allStuff);
if (!changeHandlerRegistered) {
remoteStorage.stuff.onChange(renderTheView);
changeHandlerRegistered = true;
}
});
}
renderTheView();//called once on page load |
This is very complicated with not much benefit as well. There won't be any change events until things actually change remotely. We register those before even doing the |
@skddc Under caching strategy 'ALL', there will be 'remote'-origin change events during initial sync, as the local store is filling up with data it's fetching from the remote store. Also, you would get all the 'local'-origin events, don't you? |
|
|
And you're absolutely sure that no change events are received during initial sync? Can you add a debug statement on line https://github.com/skddc/webmarks/blob/master/app/routes/application.js#L15? |
No, I'm not. Thinking about it, it would be wrong if there weren't any. But it doesn't matter anyway, as we're setting the model to the |
So you're not fixing the OP's problem, then, which was:
You need an (Ember-independent) mechanism that suppresses those small updates until initial sync is complete. |
Yes, because you're not using the events in order to load the initial data. It is still the reason we fixed the getAll behaviour and the intuitive way to go for app developers, as almost any other data persistence library gives you a call like that by default.
This has nothing at all to do with Ember! Exactly zero. It's just loading the objects into your collection that you're rendering, which you would do with any framework and in any normal app implementation. |
By the way, from your comments I get the feeling that you're only implementing example apps with next to no code, especially not models, collections, bindings, etc.. That is a very different point of view and it doesn't help people using an app framework like Angular, Ember, Marionette, React and whatnot, as they usually do something very similar to what I posted as an example and don't even have to worry about the problems you have without these concepts. |
I don't understand the distinction between
and its opposite,
I understand you make a distinction between loading data "into the collection" and displaying data on the screen, but I don't know enough about mvc to understand it, sorry. I'll just create a FAQ entry based on the first two solution, and then you can add the third option which in #732 (comment) you say is simpler. |
Ok. |
I wasn't looking for an "at least once" thing. To me it looks like Here's some (pseudo)code that shows what my idea is. Does this make sense? remoteStorage.myModule.privateClient.cache("")
remoteStorage.on("features-loaded", function(){
remoteStorage.myModule.privateClient.getAll("mypath/").then(function(data){
var dirty = false
// store and views are not bound in any way
store.setData(data)
views.update()
remoteStorage.myModule.privateClient.on("change", function(event){
if(event.newValue && event.oldValue){
console.log(event.path + " was updated")
}else if(event.newValue){
console.log(event.path + " was created")
store.put(event.newValue)
dirty = true
}else if(event.oldValue){
console.log(event.path + " was deleted")
store.remove(event.oldValue.id)
dirty = true
}
})
remoteStorage.sync.on("done", function(){
if(dirty){
views.update()
dirty = false
}
})
})
}) |
Right, that makes sense,yes. Although you really want to use |
Ok. The current event docs are not very helpful ("features-loaded: fired when all features are loaded"). Where do you add it? Where are these FAQs? |
They don't exist yet, I'm doing a doc sprint the week of 7 July, then I'll create them. a bit like howto-guides. Either in the starter-kit, or on remotestorage.io, or both. |
I also noticed that the |
FYI: when I think we should probably emit that event on the |
In 1.0.x, there is now an event Also, the |
When syncing documents or initially loading documents there's single events for each new or updated document. If I use these events to update the UI lots of updates are made in a short time causing things to flicker or jump around in case of updated order in a list or something and it is also just inefficient. I would like to know when a sync cycle or an initial loading is done so I can use that event to trigger one single update of the UI with all the new data.
The text was updated successfully, but these errors were encountered: