Live updating data from server

I have the following code:

        var type = store.modelFor(name);
	var serializer = store.serializerFor(type.typeKey);
   	var data = $.parseJSON( message );
	var record = serializer.extractSingle(store, type, data);
	store.push(name, record);

Which is fired when the server sends a (SignalR - web sockets) message to notify the app that there has been a record updated.

I know I need to be doing 2 things which I can’t figure out:

1 : how can I see if the record exists locally without going off to the server to fetch it - I only want to update records that exist locally so as to not overload the store

2: calling store.push seems to want to reflect the changes to the record to the server - this is not wanted as obviously the changes came from the server - how can I stop this?

w

Answering part 1!

DS.Store.hasRecordForId(type, id)

for part 2, take a look at:

Hi

I don’t really want to have a seperate update per model. I’d like this to be as generic as possible, that way the server can just send the models to update in the client at they just get dealt with.

Kind of like this:

socket.on('message', function (message) {
  var hash = message.data;
  var type = store.modelFor(message.model);
  var fields = Ember.get(type, 'fields');
  fields.forEach(function(field) {
    var payloadField = Ember.String.underscore(field);
    if (field === payloadField) { return; }
      hash[field] = hash[payloadField];
      delete hash[payloadField];
  });
  store.push(message.model, hash);
});

From here

Except I can’t figure out how to get that working.

update just passes a boolean as the third parameter to push. You would need to pull the ID out of each data.

try:

Well, re-reading your initial post…

That sounds like a bug… it should not mark the records as dirty and should not try to push anything to the server (unless, of course, you have some custom logic that would trigger such behavior)