@@ -4,13 +4,54 @@ import { get, computed } from '@ember/object';
44const NAMESPACE = 'providers' ;
55let configuration = { } ;
66
7+ const getValue = function ( configKey ) {
8+ const configNamespace = NAMESPACE + '.' + this . get ( 'name' ) ;
9+ const propertyPath = configNamespace + '.' + configKey ;
10+ const configuration = getConfiguration ( ) ;
11+ return get ( configuration , propertyPath ) ;
12+ } ;
13+
714function configurable ( configKey , defaultValue ) {
8- return computed ( function configurableComputed ( ) {
9- var configNamespace = NAMESPACE + '.' + this . get ( 'name' ) ;
10- var propertyPath = configNamespace + '.' + configKey ;
11- let configuration = getConfiguration ( ) ;
12- var value = get ( configuration , propertyPath ) ;
15+ // want to somehow determine if should return legacy or new decorator
16+ return configurableLegacy ( configKey , defaultValue ) ;
17+ }
18+
19+ function configurableDecorator ( configKey , defaultValue ) {
20+ return function ( _target , _key , descriptor ) {
21+ const originalGetter = descriptor . get ;
22+ const getter = function ( ) {
23+ const value = getValue . call ( this , configKey ) ;
24+
25+ if ( typeof value === 'undefined' ) {
26+ if ( typeof defaultValue !== 'undefined' ) {
27+ if ( typeof defaultValue === 'function' ) {
28+ return defaultValue . call ( this ) ;
29+ } else {
30+ return defaultValue ;
31+ }
32+ } else if ( typeof originalGetter === 'function' ) {
33+ return originalGetter . call ( this ) ;
34+ } else {
35+ throw new Error (
36+ `Expected configuration value ${ configKey } to be defined for provider named ${ this . name } `
37+ ) ;
38+ }
39+ }
40+
41+ return value ;
42+ } ;
1343
44+ return {
45+ get : getter ,
46+ enumerable : false ,
47+ configurable : true ,
48+ } ;
49+ } ;
50+ }
51+
52+ function configurableLegacy ( configKey , defaultValue ) {
53+ return computed ( function configurableComputed ( ) {
54+ const value = getValue . call ( this , configKey ) ;
1455 if ( typeof value === 'undefined' ) {
1556 if ( typeof defaultValue !== 'undefined' ) {
1657 if ( typeof defaultValue === 'function' ) {
@@ -39,6 +80,12 @@ function getConfiguration() {
3980 return configuration ;
4081}
4182
42- export { configurable , configure , getConfiguration } ;
83+ export {
84+ configurable ,
85+ configurableLegacy ,
86+ configurableDecorator ,
87+ configure ,
88+ getConfiguration ,
89+ } ;
4390
4491export default { } ;
0 commit comments