lyric
April 10, 2014, 3:47am
1
Hi all, I am working for a project which use websock and embed-data to fetch data from server.
In some cases, I fetch data changes via websock from server and update the record, like code followed:
whenDataChanges: (data) ->
@store.find("comment", data.id).then((comment) ->
comment.set('text', data.text)
)
When i set property of comment record manually, it’s state become dirty, which make the problem. Because the record comes from the server, I don’t want to call .save() method to remove the state(my request payload is huge).
I searched STO and the forum, found some topics about it:
I tried to upgrade an application from Ember data 0.13 to 0.14.
I have some
record.get('stateManager').goToState('updated');
statements in my code.
It seems though that the stateManager property is gone. I found the currentState property.
How can I manually change / manipulate a record’s state in Ember data 0.14?
but them don’t work for my case. How can i remove the dirty state? Thank you all.
1 Like
I think you could try the push
method of DS.Store
. This way you your model won’t get dirty.
For example in your case
var controller = this;
...
// in the success part of your promise:
controller.store.push('comment', { id: data.id, text: data.text });
toovy
April 11, 2014, 1:51pm
3
Maybe you could manually set the state:
comment.set('currentState', DS.RootState.loaded.saved);
You can have a look at the DS.RootState object here http://emberjs.com/api/data/classes/DS.RootState.html .
Best Regards,
toovy
Rhinon
April 12, 2014, 12:01am
4
If you were doing this to set one property of many, would the exclusion of the other properties have any effect?
lyric
April 12, 2014, 4:08am
5
If I exclusion the others properties, they will became empty or zero.
push
has a third parameter: _partial
Not sure if you’ve figured out a solution to your problem, but I stumbled on your question while trying to solve the same problem in my app.
I noticed that the signature for the DS.Store push function takes an optional “_partial” parameter.
push: function(type, data, _partial) {
// _partial is an internal param used by `update`.
// If passed, it means that the data should be
// merged into the existing data, not replace it.
I was able to update portions of my data set by sending…
I guess if you pass true
, the other properties won’t be affected.
controller.store.push('comment', { id: data.id, text: data.text }, true);
1 Like
lyric
April 12, 2014, 9:22am
7
Wow, the parameter does the work. Thank you @splattne !
Also thank @toovy , Your code works too, but I prefer to use push
method.