Skip to content

Commit

Permalink
Add deprecated registry property to Application/ApplicationInstance
Browse files Browse the repository at this point in the history
Removal in #15912
  • Loading branch information
cibernox committed Dec 1, 2017
1 parent 7c6ed52 commit 78f91a8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function(/* environment, appConfig */) {
_ENABLE_DEPRECATION_OPTIONS_SUPPORT: true,
_ENABLE_WARN_OPTIONS_SUPPORT: true,
_ENABLE_SAFE_STRING_SUPPORT: true,
_ENABLE_ENUMERABLE_CONTAINS_SUPPORT: true
_ENABLE_ENUMERABLE_CONTAINS_SUPPORT: true,
_ENABLE_DEPRECATED_REGISTRY_SUPPORT: true
}
};
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
this.import('vendor/ember-k.js');
this.import('vendor/safe-string.js');
this.import('vendor/enumerable-contains.js');
this.import('vendor/deprecated-registry.js');
}
};
13 changes: 13 additions & 0 deletions tests/unit/deprecated-registry-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';
import { module, test } from 'qunit';

module('Deprecated registry');

test('that Ember.Application.registry is correctly polyfilled', assert => {
assert.equal(typeof Ember.Application.prototype.registry, 'object', 'registry is present on Ember.Application');
});

test('that Ember.ApplicationInstance.registry is correctly polyfilled', assert => {
assert.equal(typeof Ember.ApplicationInstance.prototype.registry, 'object', 'registry is present on Ember.ApplicationInstance');
});

69 changes: 69 additions & 0 deletions vendor/deprecated-registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(function () {
var _Ember;
if (typeof Ember !== 'undefined') {
_Ember = Ember;
} else {
_Ember = require('ember').default;
}

if (EmberENV && EmberENV._ENABLE_DEPRECATED_REGISTRY_SUPPORT !== true) {
return false;
}

if (!_Ember.Application.prototype.registry) {
Object.defineProperty(_Ember.Application.prototype, 'registry', {
configurable: true,
enumerable: false,
get() {
return buildFakeRegistryWithDeprecations(this, 'Application');
}
});
}

if (!_Ember.ApplicationInstance.prototype.registry) {
Object.defineProperty(_Ember.ApplicationInstance.prototype, 'registry', {
configurable: true,
enumerable: false,
get() {
return buildFakeRegistryWithDeprecations(this, 'ApplicationInstance');
}
});
}

function buildFakeRegistryWithDeprecations(instance, typeForMessage) {
let fakeRegistry = {};
let registryProps = {
resolve: 'resolveRegistration',
register: 'register',
unregister: 'unregister',
has: 'hasRegistration',
option: 'registerOption',
options: 'registerOptions',
getOptions: 'registeredOptions',
optionsForType: 'registerOptionsForType',
getOptionsForType: 'registeredOptionsForType',
injection: 'inject'
};

for (let deprecatedProperty in registryProps) {
fakeRegistry[deprecatedProperty] = buildFakeRegistryFunction(instance, typeForMessage, deprecatedProperty, registryProps[deprecatedProperty]);
}

return fakeRegistry;
}

function buildFakeRegistryFunction(instance, typeForMessage, deprecatedProperty, nonDeprecatedProperty) {
return function() {
_Ember.deprecate(
`Using \`${typeForMessage}.registry.${deprecatedProperty}\` is deprecated. Please use \`${typeForMessage}.${nonDeprecatedProperty}\` instead.`,
false,
{
id: 'ember-application.app-instance-registry',
until: '3.0.0',
url: 'https://emberjs.com/deprecations/v2.x/#toc_ember-application-registry-ember-applicationinstance-registry'
}
);
return instance[nonDeprecatedProperty](...arguments);
};
}
})();

0 comments on commit 78f91a8

Please sign in to comment.