Skip to content
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

Merged
merged 2 commits into from
Mar 6, 2018
Merged

Conversation

smfoote
Copy link
Contributor

@smfoote smfoote commented Mar 1, 2018

Add custom component manager and tests. See #16301 and ember-cli/ember-rfc176-data#43.

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,
Copy link
Member

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 };
}

/**
Copy link
Member

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({
Copy link
Member

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);
Copy link
Member

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)

@@ -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';
Copy link
Member

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?

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';
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not.

Copy link
Contributor Author

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({
Copy link
Member

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
Copy link
Member

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 => {
Copy link
Member

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)...

@@ -439,6 +440,11 @@ Ember.TextField = TextField;
Ember.TextArea = TextArea;
Ember.LinkComponent = LinkComponent;

Object.defineProperty(Ember, '_componentManager', {
Copy link
Member

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?

Copy link
Contributor Author

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 => {
Copy link
Member

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

Copy link
Contributor Author

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.

@@ -439,6 +440,11 @@ Ember.TextField = TextField;
Ember.TextArea = TextArea;
Ember.LinkComponent = LinkComponent;

Object.defineProperty(Ember, 'setComponentManager', {
Copy link
Member

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?

Copy link
Contributor Author

@smfoote smfoote Mar 2, 2018

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;
}
};
Copy link
Member

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

Copy link
Contributor Author

@smfoote smfoote Mar 5, 2018

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 ?

Copy link
Member

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

@smfoote smfoote force-pushed the custom-component-manager branch 2 times, most recently from 93a11f3 to 8cca013 Compare March 5, 2018 23:28
@rwjblue rwjblue merged commit caca9d8 into emberjs:master Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants