Comments (3)
Thanks for opening this issue, I think we could use a better composition example in the docs! The idea is, you take the innerHTML of the element (before the component is first rendered) and save it on a property. We could create this property automatically for the user, that might be nice, I'm using this pattern quite a bit.
class Parent extends Tonic {
render () {
this.children = this.children || this.root.innerHTML
return `
<div class="parent">${this.children}</div>
`
}
}
Tonic.add(Parent)
class Child extends Tonic {
render () {
return `
<div class="child">
${this.props.value}
</div>
`
}
}
Tonic.add(Child)
INPUT HTML
<parent>
<child value="hello world"></child>
</parent>
OUTPUT HTML
(Like web-components, we want to preserve the host elements)
<parent>
<div class="parent">
<child>
<div class="child">hello world</div>
</child>
</div>
</parent>
from tonic.
I thought about this a bit and I decided it's totally reasonable to add some sugar for this (especially since I use the pattern a lot when creating components). I added a section to the docs (https://hxoht.github.io/components/#custom). Let me know what you think, if you like it we can close this out. :)
from tonic.
Looks great! Thanks. :)
from tonic.
Related Issues (20)
- Revise public/private methods
- Check that second parameter of Tonic.add is a kebab-case string (if provided)
- Numbers and booleans arenβt replaced correctly HOT 5
- Async functions are stringified HOT 1
- Multiple class names are not added correctly HOT 3
- Tonic Theme HOT 1
- Cannot pass a `Map` instance as a property HOT 2
- Congratulations! HOT 2
- Composition Issues HOT 6
- Slots HOT 3
- [Question] FAQ? How to use? HOT 2
- When rerending, input focus is lost HOT 2
- Mangling error fixed with Terser, not UglifyJS
- this.children gets overwritten by Tonic changes HOT 3
- Docs request β Can render a component assigned to a variable? HOT 1
- npm install fails
- SSR docs
- Home page has no links to the code or examples HOT 2
- docs in README.md
- Release Tonic 15.0.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tonic.