开发者

Compare the differences between two backbone models?

开发者 https://www.devze.com 2023-04-11 04:23 出处:网络
I have an app that updates backbone models between two clients over websockets. I\'d like to keep the sync procedure very generalized so I\'m aiming to be able to deflate the model send JSON over th

I have an app that updates backbone models between two clients over websockets.

I'd like to keep the sync procedure very generalized so I'm aiming to be able to deflate the model send JSON over the wire and inflate on the other client.

I have all this working perfectly except right now I inflate the model in place clobbering the old one. As far as I know this means开发者_Go百科 everything changes state and everything renders itself again.

How should I go about comparing and applying only changed attributes of the model on the receiving end?

Thanks!!!


I assume you're taking a hash of attributes from the remote model, and calling

localModel.set remoteModelHash

In that case, for each of the attributes in that hash, a change event is triggered only for those whose values are different (more precisely, those who fail a _.isEqual test). Which means that you shouldn't have views rendering unnecessarily, etc.

You can test this by checking

localModel.changedAttributes()

after the set call.

0

精彩评论

暂无评论...
验证码 换一张
取 消