Last active
August 8, 2020 00:06
-
-
Save neborn/5e03de9784a2da54d9e400cc6c35d1b9 to your computer and use it in GitHub Desktop.
Configurations in the Container
This file contains hidden or 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
import Component from '@glimmer/component'; | |
import { inject as configuration } from '../utils/configuration'; | |
export default class extends Component { | |
@configuration | |
myConfiguration; | |
get sameConfiguration() { | |
return this.args.configuration == this.myConfiguration; | |
} | |
} |
This file contains hidden or 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
import Configuration from '../utils/configuration'; | |
import { inject as service } from '@ember/service'; | |
export default class MyConfiguration extends Configuration { | |
@service | |
myService; | |
get options() { | |
return [ | |
this.myService.getOption(0), | |
this.myService.getOption(1) | |
]; | |
} | |
} |
This file contains hidden or 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
import Controller from '@ember/controller'; | |
import { inject as configuration } from '../utils/configuration'; | |
export default class ApplicationController extends Controller { | |
@configuration | |
myConfiguration; | |
} |
This file contains hidden or 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
import Service from '@ember/service'; | |
export default class MyService extends Service { | |
getOption(idx) { | |
return { | |
name: `Option ${idx}` | |
}; | |
} | |
} |
This file contains hidden or 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
This file contains hidden or 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
import { getOwner, setOwner } from '@ember/application'; | |
/** | |
* Base class that matches the containers expectations of a static create method that it will use to instantiate an instance of the class when a lookup is performed | |
* For an example of an actual configuration class see configurations/my-configuration.js | |
*/ | |
export default class Configuration { | |
static create(something) { | |
const configuration = new this(); | |
setOwner(configuration, getOwner(something)); | |
return configuration; | |
} | |
} | |
/** | |
* inject property decorator that can be used just like the service inject decorator, but for looking up classes in the components directory instead of the services directory | |
*/ | |
export function inject(clazz, propertyName, config) { | |
config.initializer = function() { | |
return getOwner(this).lookup(`configuration:${propertyName}`); | |
} | |
return config; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment