Update Ember Model

This commit is contained in:
Piotr Sarnacki 2013-12-09 17:37:31 +01:00
parent edb4e19309
commit 5b5a9d7839

View File

@ -163,14 +163,14 @@ Ember.RecordArray = Ember.ArrayProxy.extend(Ember.Evented, {
set(this, 'isLoaded', false); set(this, 'isLoaded', false);
if (modelClass._findAllRecordArray === this) { if (modelClass._findAllRecordArray === this) {
modelClass.adapter.findAll(modelClass, this); return modelClass.adapter.findAll(modelClass, this);
} else if (this._query) { } else if (this._query) {
modelClass.adapter.findQuery(modelClass, this, this._query); return modelClass.adapter.findQuery(modelClass, this, this._query);
} else { } else {
promises = this.map(function(record) { promises = this.map(function(record) {
return record.reload(); return record.reload();
}); });
Ember.RSVP.all(promises).then(function(data) { return Ember.RSVP.all(promises).then(function(data) {
self.notifyLoaded(); self.notifyLoaded();
}); });
} }
@ -252,7 +252,7 @@ var get = Ember.get, set = Ember.set;
Ember.ManyArray = Ember.RecordArray.extend({ Ember.ManyArray = Ember.RecordArray.extend({
_records: null, _records: null,
originalContent: null, originalContent: [],
isDirty: function() { isDirty: function() {
var originalContent = get(this, 'originalContent'), var originalContent = get(this, 'originalContent'),
@ -641,6 +641,7 @@ Ember.Model = Ember.Object.extend(Ember.Evented, {
}, },
reload: function() { reload: function() {
this.getWithDefault('_dirtyAttributes', []).clear();
return this.constructor.reload(this.get(get(this.constructor, 'primaryKey'))); return this.constructor.reload(this.get(get(this.constructor, 'primaryKey')));
}, },
@ -950,7 +951,7 @@ Ember.Model.reopenClass({
_executeBatch: function() { _executeBatch: function() {
var batchIds = this._currentBatchIds, var batchIds = this._currentBatchIds,
batchRecordArrays = this._currentBatchRecordArrays, batchRecordArrays = this._currentBatchRecordArrays || [],
batchDeferreds = this._currentBatchDeferreds, batchDeferreds = this._currentBatchDeferreds,
self = this, self = this,
requestIds = [], requestIds = [],
@ -984,7 +985,7 @@ Ember.Model.reopenClass({
batchRecordArrays[i].loadForFindMany(self); batchRecordArrays[i].loadForFindMany(self);
} }
if(batchDeferreds) { if (batchDeferreds) {
for (i = 0, l = batchDeferreds.length; i < l; i++) { for (i = 0, l = batchDeferreds.length; i < l; i++) {
var resolveWith = Ember.get(batchDeferreds[i], 'resolveWith'); var resolveWith = Ember.get(batchDeferreds[i], 'resolveWith');
batchDeferreds[i].resolve(resolveWith); batchDeferreds[i].resolve(resolveWith);
@ -1325,6 +1326,15 @@ function deserialize(value, type) {
} }
} }
function serialize(value, type) {
if (type && type.serialize) {
return type.serialize(value);
} else if (type && Ember.Model.dataTypes[type]) {
return Ember.Model.dataTypes[type].serialize(value);
} else {
return value;
}
}
Ember.attr = function(type, options) { Ember.attr = function(type, options) {
return Ember.computed(function(key, value) { return Ember.computed(function(key, value) {
@ -1349,7 +1359,7 @@ Ember.attr = function(type, options) {
dataValue = data[dataKey] = value; dataValue = data[dataKey] = value;
} }
if (dataValue !== value) { if (dataValue !== serialize(value, type)) {
dirtyAttributes.pushObject(key); dirtyAttributes.pushObject(key);
} else { } else {
dirtyAttributes.removeObject(key); dirtyAttributes.removeObject(key);
@ -1472,8 +1482,8 @@ Ember.RESTAdapter = Ember.Adapter.extend({
record.didDeleteRecord(); record.didDeleteRecord();
}, },
ajax: function(url, params, method) { ajax: function(url, params, method, settings) {
return this._ajax(url, params, method || "GET"); return this._ajax(url, params, (method || "GET"), settings);
}, },
buildURL: function(klass, id) { buildURL: function(klass, id) {