dist/globals/ember-data.prod.js in ember-data-source-2.11.1 vs dist/globals/ember-data.prod.js in ember-data-source-2.11.2

- old
+ new

@@ -4,11 +4,11 @@ /*! * @overview Ember Data * @copyright Copyright 2011-2016 Tilde Inc. and contributors. * Portions Copyright 2011 LivingSocial Inc. * @license Licensed under MIT license (see license.js) - * @version 2.11.1 + * @version 2.11.2 */ var loader, define, requireModule, require, requirejs; (function(global) { @@ -2386,11 +2386,11 @@ setOwner(createOptions, (0, _emberDataPrivateUtils.getOwner)(this.store)); } else { createOptions.container = this.store.container; } - this._record = this.modelClass._create(createOptions); + this._record = this.store.modelFactoryFor(this.modelName).create(createOptions); this._triggerDeferredTriggers(); } return this._record; @@ -4132,19 +4132,11 @@ return this._internalModel._data; } }); Model.reopenClass({ - /** - Alias DS.Model's `create` method to `_create`. This allows us to create DS.Model - instances from within the store, but if end users accidentally call `create()` - (instead of `createRecord()`), we can raise an error. - @method _create - @private - @static - */ - _create: Model.create, + isModel: true, /** Override the class' `create()` method to raise an error. This prevents end users from inadvertently calling `create()` instead of `createRecord()`. The store is still able to create instances @@ -4152,14 +4144,10 @@ `DS.Model` use [store.createRecord](DS.Store.html#method_createRecord). @method create @private @static */ - create: function () { - throw new _ember.default.Error("You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set."); - }, - /** Represents the model's class name as a string. This can be used to look up the model through DS.Store's modelFor method. `modelName` is generated for you by Ember Data. It will be a lowercased, dasherized string. For example: @@ -8903,10 +8891,11 @@ this.typeMaps = {}; this.recordArrayManager = _emberDataPrivateSystemRecordArrayManager.default.create({ store: this }); this._pendingSave = []; + this._modelClassCache = new _emberDataPrivateSystemEmptyObject.default(); this._instanceCache = new _emberDataPrivateSystemStoreContainerInstanceCache.default((0, _emberDataPrivateUtils.getOwner)(this), this); //Used to keep track of all the find requests that need to be coalesced this._pendingFetch = MapWithDefault.create({ defaultValue: function () { return []; @@ -10446,20 +10435,21 @@ } else { mixin = owner._lookupFactory('mixin:' + normalizedModelName); } if (mixin) { + var ModelForMixin = _emberDataModel.default.extend(mixin); + ModelForMixin.reopenClass({ + __isMixin: true, + __mixin: mixin + }); + //Cache the class as a model - owner.register('model:' + normalizedModelName, _emberDataModel.default.extend(mixin)); + owner.register('model:' + normalizedModelName, ModelForMixin); } - var factory = this.modelFactoryFor(normalizedModelName); - if (factory) { - factory.__isMixin = true; - factory.__mixin = mixin; - } - return factory; + return this.modelFactoryFor(normalizedModelName); }, /** Returns the model class for the particular `modelName`. The class of a model might be useful if you want to get a list of all the @@ -10470,35 +10460,67 @@ @param {String} modelName @return {DS.Model} */ modelFor: function (modelName) { - var factory = this.modelFactoryFor(modelName); + var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName); + var factory = this.modelFactoryFor(normalizedModelName); if (!factory) { //Support looking up mixins as base types for polymorphic relationships - factory = this._modelForMixin(modelName); + factory = this._modelForMixin(normalizedModelName); } if (!factory) { - throw new EmberError("No model was found for '" + modelName + "'"); + throw new EmberError("No model was found for '" + normalizedModelName + "'"); } + + return this._modelFor(normalizedModelName); + }, + + /* + @private + */ + _modelFor: function (modelName) { + var maybeFactory = this._modelFactoryFor(modelName); + // for factorFor factory/class split + return maybeFactory.class ? maybeFactory.class : maybeFactory; + }, + + _modelFactoryFor: function (modelName) { + var factory = this._modelClassCache[modelName]; + + if (!factory) { + factory = this.modelFactoryFor(modelName); + + if (!factory) { + //Support looking up mixins as base types for polymorphic relationships + factory = this._modelForMixin(modelName); + } + if (!factory) { + throw new EmberError('No model was found for \'' + modelName + '\''); + } + + // interopt with the future + var klass = (0, _emberDataPrivateUtils.getOwner)(this).factoryFor ? factory.class : factory; + + // TODO: deprecate this + klass.modelName = klass.modelName || modelName; + + this._modelClassCache[modelName] = factory; + } factory.modelName = factory.modelName || (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName); return factory; }, modelFactoryFor: function (modelName) { - var normalizedKey = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName); - + var trueModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName); var owner = (0, _emberDataPrivateUtils.getOwner)(this); if (owner.factoryFor) { - var MaybeModel = owner.factoryFor('model:' + normalizedKey); - var MaybeModelFactory = MaybeModel && MaybeModel.class; - - return MaybeModelFactory; + return owner.factoryFor('model:' + trueModelName); } else { - return owner._lookupFactory('model:' + normalizedKey); + return owner._lookupFactory('model:' + trueModelName); } }, /** Push some data for a given type into the store. @@ -18707,10 +18729,10 @@ */ deserialize: null }); }); define("ember-data/version", ["exports"], function (exports) { - exports.default = "2.11.1"; + exports.default = "2.11.2"; }); define("ember-inflector", ["exports", "ember", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (exports, _ember, _emberInflectorLibSystem, _emberInflectorLibExtString) { _emberInflectorLibSystem.Inflector.defaultRules = _emberInflectorLibSystem.defaultRules; _ember.default.Inflector = _emberInflectorLibSystem.Inflector;