和有什么区别
// 'this' is the controller
this.get('model').save();
和
// 'this' is the controller
this.get('model').get('store').commit();
? 在我做的小测试中,他们都给了我相同的结果。我应该使用哪一个?
我查看了第一个,它调用
DS.Model = Ember.Object.extend(
...
save: function() {
this.get('store').scheduleSave(this);
var promise = new Ember.RSVP.Promise();
this.one('didCommit', this, function() {
promise.resolve(this);
});
return promise;
},
this.get('store').scheduleSave(this)
那么问题就变成了,和之间的主要区别是this.get('store').commit()
什么?
DS.Store = Ember.Object.extend(DS._Mappable, {
...
scheduleSave: function(record) {
get(this, 'currentTransaction').add(record);
once(this, 'flushSavedRecords');
},
...
/**
This method delegates committing to the store's implicit
transaction.
Calling this method is essentially a request to persist
any changes to records that were not explicitly added to
a transaction.
*/
commit: function() {
get(this, 'defaultTransaction').commit();
},
我不确定哪个更好。我倾向于 save() 因为它似乎环绕着商店。
(我在github上找不到这些代码,不知道emberjs的github版本还是amazonaws版本是最新的。这里是github上的类似版本:model的save()调用store的scheduleSave(),store的commit () )