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

Should localStore be the source of truth? #12

Open
tute opened this issue Jul 7, 2014 · 2 comments
Open

Should localStore be the source of truth? #12

tute opened this issue Jul 7, 2014 · 2 comments

Comments

@tute
Copy link
Contributor

tute commented Jul 7, 2014

When updating a record, the older version seems to persist in localStore. It happens like this:

  1. In models index, go to edit form for an object.
  2. Perform the update.
  3. Be redirected to index, model hook fires but the enqueued update of step 2 didn't yet arrive to the server.
  4. Fetch the index JSON object, with the not-yet-updated name.
  5. Where's my update?

Now if I retrigger the index model hook, or reload, the update is of course there. Should localStore be the source of truth, and push changes always but not pull? Should online find not fire if there's enqueued operations? I'm not sure how to deal with this issue yet.

Thank you for your time.

@tute
Copy link
Contributor Author

tute commented Jul 7, 2014

An in-app workaround to query online only if there's no outstanding operations:

export default Ember.Route.extend({
  model: function() {
    if (Object.keys(this.queuedOps()).length) {
      return this.store.find("farm");
    } else {
      return this.emberSync.find("farm");
    }
  },

  queuedOps: function() {
    var queuedOps;
    queuedOps = JSON.parse(window.localStorage.getItem('namespace'));
    if (queuedOps && queuedOps.emberSyncQueueModel) {
      return queuedOps.emberSyncQueueModel.records;
    } else {
      return {};
    }
  }
});

@kurko
Copy link
Owner

kurko commented Jul 7, 2014

I like your approach, except that we shouldn't just check the queue. We should check if a particular item with same type and id is present. In that case, offlineStore takes precedence.

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

No branches or pull requests

2 participants