Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

DS.Store.load should not overwrite the old information #462

Closed
ftokarev opened this Issue · 3 comments

3 participants

Fyodor Tokarev Peter Wagenet Yehuda Katz
Fyodor Tokarev

Usecase: server pushes updates to already loaded records. In order to save bandwidth, the server pushes only changed attributes and not the whole record. As a result, we end up with the record with a lot of missing attributes.

As a work-around, I've implemented this:

App.Store = DS.Store.extend({

  load: function (type, id, hash) {
    var id = id+'',
        typeMap = this.typeMapFor(type),
        clientId = typeMap.idToCid[id],
        currentHash, resultHash;

    if (clientId) {
      var record = this.recordCache[clientId];
      if (record) {
        // record is materialized and data is processed
        currentHash = this.getDataOfMaterializedRecord(record);
      } else {
        // record is not materialized yet, its hash is cached
        currentHash = this.clientIdToHash[clientId];
      }
      resultHash = $.extend({}, currentHash, hash);
    } else {
      resultHash = hash;
    }

    this._super(type, id, resultHash);
  },

  getDataOfMaterializedRecord: function (record) {
    var data = record.get("data");
    return $.extend({}, data.attributes, data.belongsTo, data.hasMany);
  },
});
Peter Wagenet
Owner

Right now we don't support partial loads because there are a number of unresolved issues around this. However, this is something we'd like to support in the future. For now I'll leave this open. @wycats, @tomdale if you want to track this elsewhere it's probably fine to close.

Yehuda Katz wycats was assigned
Yehuda Katz
Owner

I'm going to add store.update that contains a partial hash and merges it in to the existing data.

Yehuda Katz
Owner

Done: 97fad9c

Yehuda Katz wycats closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.