-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add deprecated
registry
property to Application/ApplicationInstance
Removal in #15912
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} | ||
})(); |