-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom component manager #16308
Custom component manager #16308
Conversation
features.json
Outdated
@@ -8,7 +8,7 @@ | |||
"ember-routing-router-service": true, | |||
"ember-engines-mount-params": true, | |||
"ember-module-unification": null, | |||
"glimmer-custom-component-manager": null, | |||
"glimmer-custom-component-manager": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to set this back to null
to properly test with and without the feature.
@@ -198,38 +199,64 @@ export default class CurlyComponentManager extends AbstractManager<ComponentStat | |||
return { positional: EMPTY_ARRAY, named }; | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should likely be changed to /*
(since /**
will be picked up as a YUIDoc comment)
export const COMPONENT_MANAGER = symbol('COMPONENT_MANAGER'); | ||
|
||
export function componentManager(obj: any, managerId: String) { | ||
obj.reopenClass({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. I don’t think we need to require reopenClass
to be present (and therefore precluding native classes)...
if (!managerId) { return; } | ||
|
||
let manager = owner.lookup(`component-manager:${managerId}`) as ComponentManager<ComponentStateBucket, DefinitionState>; | ||
assert(`Could not find custom component manager '${managerId}'`, !!manager); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include the component in the assertion message (otherwise this message isn’t terribly helpful)
packages/ember-glimmer/lib/index.ts
Outdated
@@ -300,7 +300,9 @@ export { default as AbstractComponentManager } from './component-managers/abstra | |||
// rather than the problem was solved | |||
// DebugStack should just test the assert message | |||
// it supports for example | |||
export { UpdatableReference } from './utils/references'; | |||
export { UpdatableReference, RootReference } from './utils/references'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is RootReference
used for outside of ember-glimmer?
packages/ember-glimmer/lib/index.ts
Outdated
export { default as iterableFor } from './utils/iterable'; | ||
export { default as DebugStack } from './utils/debug-stack'; | ||
export { default as OutletView } from './views/outlet'; | ||
export { default as CustomComponentManager } from './component-managers/custom'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to export this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it's needed in the test file, which does not seem to be able to import from lib
.
* by passing custom hooks. | ||
*/ | ||
registerCustomComponentManager(overrides = {}) { | ||
let options = Object.assign({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be updated to use assign from ember-utils (Object.assign isn’t available on all tested platforms).
@@ -14,5 +14,6 @@ export { | |||
htmlSafe, | |||
SafeString, | |||
DOMChanges, | |||
isHTMLSafe | |||
isHTMLSafe, | |||
COMPONENT_MANAGER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t believe this is needed
} | ||
|
||
export function collectChildViews(view, registry) { | ||
let ids = []; | ||
let views = []; | ||
|
||
view[CHILD_VIEW_IDS].forEach(id => { | ||
(CHILD_VIEW_IDS.get(view) || []).forEach(id => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this should be split up on multiple lines, and in the case where CHILD_VIEW_IDS.get(view)
is undefined we can return early (e.g. no need for the forEach
)...
packages/ember/lib/index.js
Outdated
@@ -439,6 +440,11 @@ Ember.TextField = TextField; | |||
Ember.TextArea = TextArea; | |||
Ember.LinkComponent = LinkComponent; | |||
|
|||
Object.defineProperty(Ember, '_componentManager', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s call it setComponentManager
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sans underscore?
view[CHILD_VIEW_IDS].forEach(id => { | ||
let view = registry[id]; | ||
if (childViews) { | ||
(CHILD_VIEW_IDS.get(view) || []).forEach(id => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to query the weakmap again here, you can reliably do childViews.forEach
directly (due to the guard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoot - you're totally right. I missed that.
packages/ember/lib/index.js
Outdated
@@ -439,6 +440,11 @@ Ember.TextField = TextField; | |||
Ember.TextArea = TextArea; | |||
Ember.LinkComponent = LinkComponent; | |||
|
|||
Object.defineProperty(Ember, 'setComponentManager', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
darn, I'm sorry for the run around here (I know you implemented exactly what I said in the last comment), I think this still needs to be underscored
Can you change it to be _setComponentManager
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, I did _setComponentManager
first, then backed off. Shoulda gone with my gut.
static get [COMPONENT_MANAGER]() { | ||
return managerId; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to do this here instead of just mutating the class? The two branches do different things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying this should be
obj[COMPONENT_MANAGER] = managerId;
instead of returning a new, extended class? That works for me. @rwjblue ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sounds good to me
Also add componentManager to the Ember global for export
93a11f3
to
8cca013
Compare
Add custom component manager and tests. See #16301 and ember-cli/ember-rfc176-data#43.