-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Should component.mount be part of the public API? #150
Comments
In #149 |
I think this should definitely be public api. For example when integrating with other frameworks, or when you want completely custom components that render a Clarifying the lifecycles and distinction between |
But you can always render a component by instantiating it like: import SomeComponent from './SomeComponent.html'
const comp = new SomeComponent({
target: someNode
}); I don't see way the user needs to separate the creating and mount phase of a component? |
Hey guys, Note that my usage of If this were more clearly delineated (i.e, in a "FAQ: How do I dynamically mount components?") then I'd see no issue with removing |
There's nothing special about export default {
onrender() {
const RouteConstructor = this.get('route')
- const currentComponent = new RouteConstructor({})
+ const currentComponent = new RouteConstructor({
+ target: this.refs.container
+ })
- currentComponent.mount(this.refs.container)
-
currentComponent.on('navigate', () => {
console.log('test')
})
Bitter experience has taught me that it's much better to limit the API to what you need today and let people hack around the limitations (e.g. if you really wanted |
Yeah, I tried to convey that I thought that in past tense - Preaching to the choir here! 😄 |
I've just released 1.2.2 which removes |
I actually missed this when it was introduced – slaps self on wrist for not paying close enough attention to #91 – but via #149 I just realised we now have a
component.mount(node)
method.Obviously we need that for nested components, since
mount
happens at a separate time to initialisation, but should it be a public method (as opposed to e.g. an undocumented private_mount
method)?My instinct is that it shouldn't, because once you have
mount
, you kind of have to haveunmount
(which is different fromteardown
, but in a slightly confusing way), adding additional code to components that the vast majority of people will never use. And it invites additionalonmount
andonunmount
lifecycle hooks, which muddy the API without that much benefit. Once these things make it into the design, you're basically stuck maintaining them (and explaining the distinction betweenrender
/mount
andteardown
/unmount
to confused newcomers) forever.The text was updated successfully, but these errors were encountered: