Repository navigation
RFC: Default Container Values - #34
jamesarosen wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
This overlaps with the resolver based fallback system of ember-cli / module based apps. Is their a way we can utilize that flow instead of introducing something new? I would prefer to add an inspectable resolver based load-path to set priority of defaults, then a last-one-wins registration system.
There was a problem hiding this comment.
The Registry fallback system happens with a linked list of parent registries. If there were a registry just for the addon that Ember inserts in the chain, and if the addon could access its own registry somehow, we could do it there:
export default {
name: 'i18n',
initialize: function(container, application) {
const i18nRegistry = container.lookup('registry:ember-i18n');
i18nRegistry.alias('i18n:plural-form', 'ember-i18n@util:plural-form');
}
};or possibly
const PUBLIC_API = {
'i18n:plural-form': 'ember-i18n@util:plural-form',
'i18n:store': 'ember-i18n@store:main'
};
i18nRegistry.normalize = function(fullName) {
return PUBLIC_API[fullName] || fullName;
};Aesthetically, I like the idea of reusing normalize. As an addon author, I like the idea of a public API method on Container or Registry that handles aliasing for me.
|
I don't agree with the nature of this RFC. It appears to promote the idea of hacking around namespaces. I think this can be very error prone. You can get what you want today with addons. For example, if you have an addon asset called import default Ember from 'ember';
export default Ember.Object.export({
...
});if you expect this to be a class that the end-user is intended to override then the end-user should be using a class in the app namespace and not the addon namespace. So you should include an app wrapper class that is the default intended to be overridden import En from 'ember-i18n/plurals/en';
export default En.extend({
...
});Now the end-user can simply provide their own version of this file in their own app: import En from 'ember-i18n/plurals/en';
export default En.extend({
...
});I have been using this pattern in several of my addons and it has worked well. Alternatively, I am selectively falling back to the namespace as default lookup in ember-validations: https://github.com/dockyard/ember-validations/blob/master/addon/mixin.js#L43-L63 but in this case there is a more complex lookup algorithm than just app => addon. |
I like this. It's at odds with something I was trying to do yesterday, but I can change course. I've been trying to extract lots of pure functions into their own
|
|
@bcardarella I think I've come around to exporting things in |
In particular: * The RFC associated with #127 should have had a link to #19 as well (and has been assigned RFC #19); it also was revised to match the markdown href style of other RFCs. * RFC #34 needed its header entries filled in, * RFC #123 had a typo in its header, and * RC #155 was revised to match the markdown href style of other RFCs.
No description provided.