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 01ab5d5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion 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,7 +609,7 @@ 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(
let ret = `<${ this[NAME_KEY] || getName(this) || FACTORY_FOR.get(this) || this.constructor.toString()}:${guidFor(
this
)}${extension}>`;

Expand Down
19 changes: 18 additions & 1 deletion packages/ember/index.js
Expand Up @@ -201,7 +201,24 @@ 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'](assert) {
expectDeprecation(() => {
Ember.NAME_KEY;
}, /`NAME_KEY` is deprecated/);
}

'@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 01ab5d5

Please sign in to comment.