Skip to content

Commit

Permalink
[CLEANUP] use debug helpers from ember-data/debug
Browse files Browse the repository at this point in the history
By this, the calls to `assert`, `warn` etcetera are corectly stripped
when a new production build is created.

(cherry picked from commit 27a2a18)

Conflicts:
	addon/serializers/json-api-serializer.js
	addon/serializers/json-serializer.js
	addon/system/model/errors.js
	addon/system/model/internal-model.js
	addon/system/model/model.js
	addon/system/relationships/has-many.js
	addon/system/relationships/state/relationship.js
	addon/system/store.js
	addon/system/store/finders.js
  • Loading branch information
pangratz authored and bmac committed Dec 12, 2015
1 parent 5cab54a commit 86cfaaa
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 109 deletions.
3 changes: 2 additions & 1 deletion addon/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from "ember";
import { warn } from "ember-data/debug";
/**
Ember Data
@module ember-data
Expand All @@ -12,7 +13,7 @@ if (Ember.VERSION.match(/^1\.([0-9]|1[0-2])\./)) {
}

if (Ember.VERSION.match(/^1\.13\./)) {
Ember.warn(`Use of Ember Data 2+ with Ember 1.13 is unsupported. Please upgrade your version of Ember to 2.0 or higher.`, false, {
warn(`Use of Ember Data 2+ with Ember 1.13 is unsupported. Please upgrade your version of Ember to 2.0 or higher.`, false, {
id: 'ds.version.ember-1-13'
});
}
Expand Down
4 changes: 3 additions & 1 deletion addon/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { warn } from "ember-data/debug";

var get = Ember.get;
var set = Ember.set;
var camelize = Ember.String.camelize;
Expand Down Expand Up @@ -331,7 +333,7 @@ export default Ember.Mixin.create({
_serializeEmbeddedHasMany: function(snapshot, json, relationship) {
let serializedKey = this.keyForAttribute(relationship.key, 'serialize');

Ember.warn(
warn(
`The embedded relationship '${serializedKey}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`,
Ember.typeOf(snapshot.hasMany(relationship.key)) !== 'undefined',
{ id: 'ds.serializer.embedded-relationship-undefined' }
Expand Down
5 changes: 3 additions & 2 deletions addon/serializers/json-api-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@module ember-data
*/

import { runInDebug, warn } from 'ember-data/debug';
import JSONSerializer from 'ember-data/serializers/json-serializer';
import normalizeModelName from 'ember-data/system/normalize-model-name';
import { pluralize, singularize } from 'ember-inflector';
Expand Down Expand Up @@ -139,7 +140,7 @@ const JSONAPISerializer = JSONSerializer.extend({
let modelName = this.modelNameFromPayloadKey(resourceHash.type);

if (!this.store._hasModelFor(modelName)) {
Ember.warn(this.warnMessageNoModelForType(modelName, resourceHash.type), false, {
warn(this.warnMessageNoModelForType(modelName, resourceHash.type), false, {
id: 'ds.serializer.model-for-type-missing'
});
return null;
Expand Down Expand Up @@ -463,7 +464,7 @@ const JSONAPISerializer = JSONSerializer.extend({
}
});

Ember.runInDebug(function() {
runInDebug(function() {
JSONAPISerializer.reopen({
warnMessageNoModelForType: function(modelName, originalType) {
return 'Encountered a resource object with type "' + originalType + '", but no model was found for model name "' + modelName + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + originalType + '"))';
Expand Down
7 changes: 4 additions & 3 deletions addon/serializers/json-serializer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert, warn } from 'ember-data/debug';
import Serializer from "ember-data/system/serializer";
import coerceId from "ember-data/system/coerce-id";
import normalizeModelName from "ember-data/system/normalize-model-name";
Expand Down Expand Up @@ -440,7 +441,7 @@ export default Serializer.extend({

let meta = this.extractMeta(store, primaryModelClass, payload);
if (meta) {
Ember.assert('The `meta` returned from `extractMeta` has to be an object, not "' + Ember.typeOf(meta) + '".', Ember.typeOf(meta) === 'object');
assert('The `meta` returned from `extractMeta` has to be an object, not "' + Ember.typeOf(meta) + '".', Ember.typeOf(meta) === 'object');
documentHash.meta = meta;
}

Expand Down Expand Up @@ -763,7 +764,7 @@ export default Serializer.extend({
@return {String} key
*/
_getMappedKey: function(key, modelClass) {
Ember.warn('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', get(modelClass, 'attributes').has(key) || get(modelClass, 'relationshipsByName').has(key), {
warn('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', get(modelClass, 'attributes').has(key) || get(modelClass, 'relationshipsByName').has(key), {
id: 'ds.serializer.no-mapped-attrs-key'
});

Expand Down Expand Up @@ -1385,7 +1386,7 @@ export default Serializer.extend({
transformFor: function(attributeType, skipAssertion) {
var transform = getOwner(this).lookup('transform:' + attributeType);

Ember.assert("Unable to find transform for '" + attributeType + "'", skipAssertion || !!transform);
assert("Unable to find transform for '" + attributeType + "'", skipAssertion || !!transform);

return transform;
}
Expand Down
11 changes: 6 additions & 5 deletions addon/serializers/rest-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@module ember-data
*/

import { assert, deprecate, runInDebug, warn } from "ember-data/debug";
import JSONSerializer from "ember-data/serializers/json-serializer";
import normalizeModelName from "ember-data/system/normalize-model-name";
import {singularize} from "ember-inflector";
Expand Down Expand Up @@ -225,7 +226,7 @@ var RESTSerializer = JSONSerializer.extend({

let meta = this.extractMeta(store, primaryModelClass, payload);
if (meta) {
Ember.assert('The `meta` returned from `extractMeta` has to be an object, not "' + Ember.typeOf(meta) + '".', Ember.typeOf(meta) === 'object');
assert('The `meta` returned from `extractMeta` has to be an object, not "' + Ember.typeOf(meta) + '".', Ember.typeOf(meta) === 'object');
documentHash.meta = meta;
}

Expand Down Expand Up @@ -263,7 +264,7 @@ var RESTSerializer = JSONSerializer.extend({

var typeName = this.modelNameFromPayloadKey(modelName);
if (!store.modelFactoryFor(typeName)) {
Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false, {
warn(this.warnMessageNoModelForKey(modelName, typeName), false, {
id: 'ds.serializer.model-for-key-missing'
});
continue;
Expand Down Expand Up @@ -383,7 +384,7 @@ var RESTSerializer = JSONSerializer.extend({
for (var prop in payload) {
var modelName = this.modelNameFromPayloadKey(prop);
if (!store.modelFactoryFor(modelName)) {
Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false, {
warn(this.warnMessageNoModelForKey(prop, modelName), false, {
id: 'ds.serializer.model-for-key-missing'
});
continue;
Expand Down Expand Up @@ -726,7 +727,7 @@ var RESTSerializer = JSONSerializer.extend({
// `keyForPolymorphicType`. If this is the case, a deprecation warning is
// logged and the old way is restored (so nothing breaks).
if (key !== typeKey && this.keyForPolymorphicType === RESTSerializer.prototype.keyForPolymorphicType) {
Ember.deprecate("The key to serialize the type of a polymorphic record is created via keyForAttribute which has been deprecated. Use the keyForPolymorphicType hook instead.", false, {
deprecate("The key to serialize the type of a polymorphic record is created via keyForAttribute which has been deprecated. Use the keyForPolymorphicType hook instead.", false, {
id: 'ds.rest-serializer.deprecated-key-for-polymorphic-type',
until: '3.0.0'
});
Expand Down Expand Up @@ -786,7 +787,7 @@ var RESTSerializer = JSONSerializer.extend({
}
});

Ember.runInDebug(function() {
runInDebug(function() {
RESTSerializer.reopen({
warnMessageNoModelForKey: function(prop, typeKey) {
return 'Encountered "' + prop + '" in payload, but no model was found for model name "' + typeKey + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + prop + '"))';
Expand Down
4 changes: 3 additions & 1 deletion addon/system/container-proxy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { deprecate } from "ember-data/debug";

/**
This is used internally to enable deprecation of container paths and provide
a decent message to the user indicating how to fix the issue.
Expand Down Expand Up @@ -28,7 +30,7 @@ ContainerProxy.prototype.registerAlias = function(source, dest, preLookup) {

ContainerProxy.prototype.registerDeprecation = function(deprecated, valid) {
var preLookupCallback = function() {
Ember.deprecate(`You tried to look up '${deprecated}', but this has been deprecated in favor of '${valid}'.`, false, {
deprecate(`You tried to look up '${deprecated}', but this has been deprecated in favor of '${valid}'.`, false, {
id: 'ds.store.deprecated-lookup',
until: '2.0.0'
});
Expand Down
3 changes: 2 additions & 1 deletion addon/system/many-array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
@module ember-data
*/
import { assert } from "ember-data/debug";
import { PromiseArray } from "ember-data/system/promise-proxies";

var get = Ember.get;
Expand Down Expand Up @@ -272,7 +273,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
var type = get(this, 'type');
var record;

Ember.assert("You cannot add '" + type.modelName + "' records to this polymorphic relationship.", !get(this, 'isPolymorphic'));
assert("You cannot add '" + type.modelName + "' records to this polymorphic relationship.", !get(this, 'isPolymorphic'));
record = store.createRecord(type.modelName, hash);
this.pushObject(record);

Expand Down
5 changes: 3 additions & 2 deletions addon/system/model/attributes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Model from "ember-data/system/model/model";
import { assert, deprecate } from "ember-data/debug";

/**
@module ember-data
Expand Down Expand Up @@ -55,7 +56,7 @@ Model.reopenClass({

this.eachComputedProperty((name, meta) => {
if (meta.isAttribute) {
Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + this.toString(), name !== 'id');
assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + this.toString(), name !== 'id');

meta.name = name;
map.set(name, meta);
Expand Down Expand Up @@ -227,7 +228,7 @@ function getDefaultValue(record, options, key) {
return options.defaultValue.apply(null, arguments);
} else {
let defaultValue = options.defaultValue;
Ember.deprecate(`Non primitive defaultValues are deprecated because they are shared between all instances. If you would like to use a complex object as a default value please provide a function that returns the complex object.`,
deprecate(`Non primitive defaultValues are deprecated because they are shared between all instances. If you would like to use a complex object as a default value please provide a function that returns the complex object.`,
typeof defaultValue !== 'object' || defaultValue === null, {
id: 'ds.defaultValue.complex-object',
until: '3.0.0'
Expand Down
7 changes: 4 additions & 3 deletions addon/system/model/internal-model.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert } from "ember-data/debug";
import merge from "ember-data/system/merge";
import RootState from "ember-data/system/model/states";
import Relationships from "ember-data/system/relationships/state/create";
Expand Down Expand Up @@ -113,7 +114,7 @@ InternalModel.prototype = {

constructor: InternalModel,
materializeRecord: function() {
Ember.assert("Materialized " + this.modelName + " record with id:" + this.id + "more than once", this.record === null || this.record === undefined);
assert("Materialized " + this.modelName + " record with id:" + this.id + "more than once", this.record === null || this.record === undefined);

// lookupFactory should really return an object that creates
// instances with the injections applied
Expand Down Expand Up @@ -563,7 +564,7 @@ InternalModel.prototype = {
},

_preloadHasMany: function(key, preloadValue, type) {
Ember.assert("You need to pass in an array to set a hasMany property on a record", Ember.isArray(preloadValue));
assert("You need to pass in an array to set a hasMany property on a record", Ember.isArray(preloadValue));
var internalModel = this;

var recordsToSet = preloadValue.map((recordToPush) => {
Expand Down Expand Up @@ -603,7 +604,7 @@ InternalModel.prototype = {
},

setId: function(id) {
Ember.assert('A record\'s id cannot be changed once it is in the loaded state', this.id === null || this.id === id || this.isNew());
assert('A record\'s id cannot be changed once it is in the loaded state', this.id === null || this.id === id || this.isNew());
this.id = id;
if (this.record.get('id') !== id) {
this.record.set('id', id);
Expand Down
13 changes: 7 additions & 6 deletions addon/system/model/model.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert, deprecate } from "ember-data/debug";
import { PromiseObject } from "ember-data/system/promise-proxies";
import Errors from "ember-data/system/model/errors";

Expand Down Expand Up @@ -750,20 +751,20 @@ var Model = Ember.Object.extend(Ember.Evented, {
// rely on the data property.
willMergeMixin: function(props) {
var constructor = this.constructor;
Ember.assert('`' + intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0] + '` is a reserved property name on DS.Model objects. Please choose a different property name for ' + constructor.toString(), !intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0]);
Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + constructor.toString(), Object.keys(props).indexOf('id') === -1);
assert('`' + intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0] + '` is a reserved property name on DS.Model objects. Please choose a different property name for ' + constructor.toString(), !intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0]);
assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + constructor.toString(), Object.keys(props).indexOf('id') === -1);
},

attr: function() {
Ember.assert("The `attr` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false);
assert("The `attr` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false);
},

belongsTo: function() {
Ember.assert("The `belongsTo` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false);
assert("The `belongsTo` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false);
},

hasMany: function() {
Ember.assert("The `hasMany` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false);
assert("The `hasMany` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false);
},

setId: Ember.observer('id', function () {
Expand Down Expand Up @@ -837,7 +838,7 @@ if (Ember.setOwner) {
configurable: true,
enumerable: false,
get() {
Ember.deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.',
deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.',
false,
{ id: 'ember-application.injected-container', until: '3.0.0' });

Expand Down
4 changes: 3 additions & 1 deletion addon/system/model/states.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
@module ember-data
*/
import { assert } from "ember-data/debug";

var get = Ember.get;
/*
This file encapsulates the various states that a record can transition
Expand Down Expand Up @@ -421,7 +423,7 @@ createdState.uncommitted.pushedData = function(internalModel) {
createdState.uncommitted.propertyWasReset = Ember.K;

function assertAgainstUnloadRecord(internalModel) {
Ember.assert("You can only unload a record which is not inFlight. `" + internalModel + "`", false);
assert("You can only unload a record which is not inFlight. `" + internalModel + "`", false);
}

updatedState.inFlight.unloadRecord = assertAgainstUnloadRecord;
Expand Down
4 changes: 3 additions & 1 deletion addon/system/promise-proxies.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { assert } from "ember-data/debug";

var Promise = Ember.RSVP.Promise;
var get = Ember.get;

Expand Down Expand Up @@ -103,7 +105,7 @@ function proxyToContent(method) {
var PromiseManyArray = PromiseArray.extend({
reload: function() {
//I don't think this should ever happen right now, but worth guarding if we refactor the async relationships
Ember.assert('You are trying to reload an async manyArray before it has been created', get(this, 'content'));
assert('You are trying to reload an async manyArray before it has been created', get(this, 'content'));
return PromiseManyArray.create({
promise: get(this, 'content').reload()
});
Expand Down
7 changes: 4 additions & 3 deletions addon/system/relationships/belongs-to.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert, warn } from "ember-data/debug";
import Model from 'ember-data/system/model';
import normalizeModelName from "ember-data/system/normalize-model-name";

Expand Down Expand Up @@ -87,7 +88,7 @@ export default function belongsTo(modelName, options) {
userEnteredModelName = normalizeModelName(userEnteredModelName);
}

Ember.assert("The first argument to DS.belongsTo must be a string representing a model type key, not an instance of " + Ember.inspect(userEnteredModelName) + ". E.g., to define a relation to the Person model, use DS.belongsTo('person')", typeof userEnteredModelName === 'string' || typeof userEnteredModelName === 'undefined');
assert("The first argument to DS.belongsTo must be a string representing a model type key, not an instance of " + Ember.inspect(userEnteredModelName) + ". E.g., to define a relation to the Person model, use DS.belongsTo('person')", typeof userEnteredModelName === 'string' || typeof userEnteredModelName === 'undefined');

opts = opts || {};

Expand All @@ -102,13 +103,13 @@ export default function belongsTo(modelName, options) {
return Ember.computed({
get: function(key) {
if (opts.hasOwnProperty('serialize')) {
Ember.warn(`You provided a serialize option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.Serializer and it's implementations http://emberjs.com/api/data/classes/DS.Serializer.html`, false, {
warn(`You provided a serialize option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.Serializer and it's implementations http://emberjs.com/api/data/classes/DS.Serializer.html`, false, {
id: 'ds.model.serialize-option-in-belongs-to'
});
}

if (opts.hasOwnProperty('embedded')) {
Ember.warn(`You provided an embedded option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html`, false, {
warn(`You provided an embedded option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html`, false, {
id: 'ds.model.embedded-option-in-belongs-to'
});
}
Expand Down
Loading

0 comments on commit 86cfaaa

Please sign in to comment.