-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(projection): Host Projection service #1756
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
Conversation
07f8973
to
75c2693
Compare
</div> | ||
`, | ||
styles: [` | ||
.outer { |
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.
Prefix class name with demo-
(same for other classes in the demo)
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.
Done.
|
||
|
||
@Injectable() | ||
export class MdProjectionService { |
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.
How about DomProjector
?
I'm generally opposed to the Service
suffix since it's somewhat meaningless; it's talking about how the class is meant to be consumed rather than what it does. Also, the service is specifically dealing with projection via DOM, hence DomProjector
.
Going along this vein, how about calling the directive DomProjectionHost
with selector dom-projection-host
? I think this makes the API a bit more explicit than <md-host>
, which doesn't give a string cue as to what it's for.
(also omitting the md
prefix since this would be something not strictly related to material design, similar to the portal and overlay directives).
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.
Done.
let child = childNodes[0]; | ||
|
||
// Replace ComponentEl by all its children, in place. | ||
this._replaceWith(componentEl, child); |
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.
Make this just an non-exported module function?
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.
Okay.
* Project an element into a host element. | ||
*/ | ||
project(ref: ElementRef, host: MdProjectionHostDirective): void { | ||
const componentEl = ref.nativeElement; |
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.
Can append as Node
on these
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.
See above.
|
||
@Injectable() | ||
export class MdProjectionService { | ||
private _replaceWith(toReplaceEl: HTMLElement, otherEl: HTMLElement) { |
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.
Could be Node
instead of HTMLElement
(less specific)
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.
We cannot replace all nodes by all nodes in the tree. Element is semantically accurate.
|
||
// Replace ComponentEl by all its children, in place. | ||
this._replaceWith(componentEl, child); | ||
while (childNodes.length) { |
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.
Reading length
on a NodeList
is notoriously slow; it's better to cache the length and for
loop.
(here and below)
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.
Done.
} | ||
|
||
/** | ||
* Project an element into a host element. |
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.
This comment needs some expansion; the key thing to communicate is that it's only the given element that is projected and not its content (children). Also worth mention when you might want to use 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.
Done.
* Project an element into a host element. | ||
*/ | ||
project(ref: ElementRef, host: MdProjectionHostDirective): void { | ||
const componentEl = ref.nativeElement; |
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.
componentEl
-> projectedEl
? (since it's not necessarily a component)
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.
Done.
const childNodes = componentEl.childNodes; | ||
let child = childNodes[0]; | ||
|
||
// Replace ComponentEl by all its children, in place. |
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.
Expand comment to something like
// We hoist all of the projected element's children out into the projected elements position
// because we *only* want to move the projected element and not its children.
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.
Done
`, | ||
styles: [` | ||
.inner { | ||
background-color: blue; |
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.
nit: these colors are totally unreadable to me (when I run the demo)
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.
Done.
@jelbourn please re-review |
@hansl I think you need to add |
@kara could you rerun the presubmits? It should pass now. |
Absolutely! Momentito. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Uh oh!
There was an error while loading. Please reload this page.