Skip to content

Commit

Permalink
add deprecation to NAME_KEY and expose setName
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed Jun 2, 2018
1 parent 6f1b060 commit bb17bcb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/ember-runtime/lib/system/core_object.js
Expand Up @@ -9,6 +9,7 @@ import {
guidFor,
getName,
setName,
NAME_KEY,
makeArray,
HAS_NATIVE_PROXY,
isInternalSymbol,
Expand Down Expand Up @@ -608,9 +609,10 @@ CoreObject.PrototypeMixin = Mixin.create({
let hasToStringExtension = typeof this.toStringExtension === 'function';
let extension = hasToStringExtension ? `:${this.toStringExtension()}` : '';

let ret = `<${getName(this) || FACTORY_FOR.get(this) || this.constructor.toString()}:${guidFor(
this
)}${extension}>`;
let ret = `<${this[NAME_KEY] ||
getName(this) ||
FACTORY_FOR.get(this) ||
this.constructor.toString()}:${guidFor(this)}${extension}>`;

return ret;
},
Expand Down
15 changes: 14 additions & 1 deletion packages/ember/index.js
Expand Up @@ -201,7 +201,20 @@ Ember.canInvoke = utils.canInvoke;
Ember.tryInvoke = utils.tryInvoke;
Ember.wrap = utils.wrap;
Ember.uuid = utils.uuid;
Ember.NAME_KEY = utils.NAME_KEY;
Ember.setName = utils.setName;

Object.defineProperty(Ember, 'NAME_KEY', {
enumerable: false,
get() {
deprecate('Using `Ember.NAME_KEY` is deprecated, please use `Ember.setName` instead', false, {
id: 'ember-name-key-usage',
until: '4.0.0',
});

return utils.NAME_KEY;
},
});

Ember._Cache = utils.Cache;

// ****container****
Expand Down
8 changes: 7 additions & 1 deletion packages/ember/tests/reexports_test.js
Expand Up @@ -34,6 +34,12 @@ moduleFor(
}, /EXTEND_PROTOTYPES is deprecated/);
}

['@test Ember.NAME_KEY is deprecated']() {
expectDeprecation(() => {
Ember.NAME_KEY;
}, 'Using `Ember.NAME_KEY` is deprecated, please use `Ember.setName` instead');
}

'@test Ember.FEATURES is exported'(assert) {
for (let feature in FEATURES) {
assert.equal(
Expand Down Expand Up @@ -64,7 +70,7 @@ let allExports = [
['canInvoke', 'ember-utils'],
['tryInvoke', 'ember-utils'],
['wrap', 'ember-utils'],
['NAME_KEY', 'ember-utils'],
['setName', 'ember-utils'],

// container
['Registry', 'container', 'Registry'],
Expand Down

0 comments on commit bb17bcb

Please sign in to comment.