diff --git a/assets/scripts/vendor/ember-data.js b/assets/scripts/vendor/ember-data.js index 8c5311c0..2fe225d5 100644 --- a/assets/scripts/vendor/ember-data.js +++ b/assets/scripts/vendor/ember-data.js @@ -1,4 +1,4 @@ -// Last commit: 8801f2e (2013-02-15 13:53:27 -0800) +// Last commit: 6d9eeaf (2013-02-20 22:27:54 +0100) (function() { @@ -151,7 +151,7 @@ DS.AdapterPopulatedRecordArray = DS.RecordArray.extend({ set(this, 'isLoaded', true); this.endPropertyChanges(); - var self = this; + var self = this; // TODO: does triggering didLoad event should be the last action of the runLoop? Ember.run.once(function() { self.trigger('didLoad'); @@ -3918,19 +3918,19 @@ DS.Model.reopen({ attributeDidChange: Ember.observer(function(record, key) { record.send('didSetProperty', { name: key }); - }) -}); + }), -function getAttr(record, options, key) { - var attributes = get(record, 'data').attributes; - var value = attributes[key]; + getAttr: function(key, options) { + var attributes = get(this, 'data').attributes; + var value = attributes[key]; - if (value === undefined) { - value = options.defaultValue; + if (value === undefined) { + value = options.defaultValue ; + } + + return value; } - - return value; -} +}); DS.attr = function(type, options) { options = options || {}; @@ -3947,7 +3947,7 @@ DS.attr = function(type, options) { if (arguments.length > 1) { Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('')` from " + this.constructor.toString(), key !== 'id'); } else { - value = getAttr(this, options, key); + value = this.getAttr(key, options); } return value; @@ -3972,18 +3972,8 @@ DS.attr = function(type, options) { var get = Ember.get, set = Ember.set, none = Ember.isNone; -DS.belongsTo = function(type, options) { - Ember.assert("The first argument DS.belongsTo must be a model type or string, like DS.belongsTo(App.Person)", !!type && (typeof type === 'string' || DS.Model.detect(type))); - - options = options || {}; - - var meta = { type: type, isRelationship: true, options: options, kind: 'belongsTo' }; - - return Ember.computed(function(key, value) { - if (arguments.length === 2) { - return value === undefined ? null : value; - } - +DS.Model.reopen({ + getBelongsTo: function(key, type, meta) { var data = get(this, 'data').belongsTo, store = get(this, 'store'), id; @@ -4000,6 +3990,22 @@ DS.belongsTo = function(type, options) { } else { return store.find(type, id); } + } +}); + +DS.belongsTo = function(type, options) { + Ember.assert("The first argument DS.belongsTo must be a model type or string, like DS.belongsTo(App.Person)", !!type && (typeof type === 'string' || DS.Model.detect(type))); + + options = options || {}; + + var meta = { type: type, isRelationship: true, options: options, kind: 'belongsTo' }; + + return Ember.computed(function(key, value) { + if (arguments.length === 2) { + return value === undefined ? null : value; + } + + return this.getBelongsTo(key, type, meta); }).property('data').meta(meta); }; @@ -4049,12 +4055,8 @@ DS.Model.reopen({ (function() { var get = Ember.get, set = Ember.set; -var hasRelationship = function(type, options) { - options = options || {}; - - var meta = { type: type, isRelationship: true, options: options, kind: 'hasMany' }; - - return Ember.computed(function(key, value) { +DS.Model.reopen({ + getHasMany: function(key, type, meta) { var data = get(this, 'data').hasMany, store = get(this, 'store'), ids, relationship; @@ -4069,6 +4071,16 @@ var hasRelationship = function(type, options) { set(relationship, 'name', key); return relationship; + } +}); + +var hasRelationship = function(type, options) { + options = options || {}; + + var meta = { type: type, isRelationship: true, options: options, kind: 'hasMany' }; + + return Ember.computed(function(key, value) { + return this.getHasMany(key, type, meta); }).property().meta(meta); }; @@ -4508,12 +4520,12 @@ DS.RelationshipChange.determineRelationshipType = function(recordType, knownSide if(options.inverse){ key = options.inverse; - otherContainerType = get(otherType, 'relationshipsByName').get(key).kind; - } + otherContainerType = get(otherType, 'relationshipsByName').get(key).kind; + } else if(assoc = DS._inverseRelationshipFor(otherType, recordType)){ key = assoc.name; otherContainerType = assoc.kind; - } + } if(!key){ return knownContainerType === "belongsTo" ? "oneToNone" : "manyToNone"; } @@ -4524,8 +4536,8 @@ DS.RelationshipChange.determineRelationshipType = function(recordType, knownSide else{ return knownContainerType === "belongsTo" ? "oneToMany" : "manyToMany"; } - } - + } + }; DS.RelationshipChange.createChange = function(firstRecordReference, secondRecordReference, store, options){ @@ -4933,7 +4945,9 @@ DS.RelationshipChangeRemove.prototype.sync = function() { if (secondRecord && firstRecord) { if(this.secondRecordKind === "belongsTo"){ + secondRecord.suspendRelationshipObservers(function(){ set(secondRecord, secondRecordName, null); + }); } else if(this.secondRecordKind === "hasMany"){ secondRecord.suspendRelationshipObservers(function(){ @@ -6469,7 +6483,6 @@ DS.JSONSerializer = DS.Serializer.extend({ sideloadedType = type.typeForRelationship(prop); - console.log('sideloadedType', type, prop, sideloadedType); if (!sideloadedType) { sideloadedType = this.sideloadMapping.get(prop); @@ -6676,7 +6689,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { occupations: [{ id: 345, title: "Tricycle Mechanic" - }] + }] }); ``` @@ -6706,12 +6719,12 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { For example, the `RESTAdapter` saves newly created records by making an Ajax request. When the server returns, the adapter calls didCreateRecord. If the server returns a response body, - it is passed as the payload. + it is passed as the payload. @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} record - @param {any} payload + @param {any} payload */ didCreateRecord: function(store, type, record, payload) { store.didSaveRecord(record); @@ -6733,7 +6746,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { Acknowledges that the adapter has finished creating several records. Your adapter should call this method from `createRecords` when it - has saved multiple created records to its persistent storage + has saved multiple created records to its persistent storage received an acknowledgement. If the persistent storage returns a new payload in response to the @@ -6743,7 +6756,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} record - @param {any} payload + @param {any} payload */ didCreateRecords: function(store, type, records, payload) { records.forEach(function(record) { @@ -6772,7 +6785,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} record - @param {any} payload + @param {any} payload */ didSaveRecord: function(store, type, record, payload) { store.didSaveRecord(record); @@ -6805,7 +6818,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} record - @param {any} payload + @param {any} payload */ didUpdateRecord: function() { this.didSaveRecord.apply(this, arguments); @@ -6824,14 +6837,14 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} record - @param {any} payload + @param {any} payload */ didDeleteRecord: function() { this.didSaveRecord.apply(this, arguments); }, /** - Acknowledges that the adapter has finished updating or deleting + Acknowledges that the adapter has finished updating or deleting multiple records. Your adapter should call this method from its `updateRecords` or @@ -6844,7 +6857,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} records - @param {any} payload + @param {any} payload */ didSaveRecords: function(store, type, records, payload) { records.forEach(function(record) { @@ -6870,7 +6883,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} records - @param {any} payload + @param {any} payload */ didUpdateRecords: function() { this.didSaveRecords.apply(this, arguments); @@ -6889,7 +6902,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type @param {DS.Model} records - @param {any} payload + @param {any} payload */ didDeleteRecords: function() { this.didSaveRecords.apply(this, arguments); @@ -6907,7 +6920,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type - @param {any} payload + @param {any} payload @param {String} id */ didFindRecord: function(store, type, payload, id) { @@ -6931,7 +6944,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type - @param {any} payload + @param {any} payload */ didFindAll: function(store, type, payload) { var loader = DS.loaderFor(store), @@ -6950,7 +6963,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type - @param {any} payload + @param {any} payload @param {DS.AdapterPopulatedRecordArray} recordArray */ didFindQuery: function(store, type, payload, recordArray) { @@ -6971,7 +6984,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { @param {DS.Store} store @param {subclass of DS.Model} type - @param {any} payload + @param {any} payload */ didFindMany: function(store, type, payload) { var loader = DS.loaderFor(store); @@ -7095,7 +7108,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { }, /** - A public method that allows you to register an enumerated + A public method that allows you to register an enumerated type on your adapter. This is useful if you want to utilize a text representation of an integer value. @@ -7107,7 +7120,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { You would then refer to the 'priority' DS.attr in your model: App.Task = DS.Model.extend({ - priority: DS.attr('priority') + priority: DS.attr('priority') }); And lastly, you would set/get the text representation on your model instance, @@ -7117,7 +7130,7 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, { Server Response / Load: { myTask: {priority: 0} } @param {String} type of the transform - @param {Array} array of String objects to use for the enumerated values. + @param {Array} array of String objects to use for the enumerated values. This is an ordered list and the index values will be used for the transform. */ registerEnumTransform: function(attributeType, objects) {