Comments (3)
That should work
from msx.
Current test output:
ok 15 <Component/> -> Component
ok 16 <Component></Component> -> Component
ok 17 <Component>X</Component> -> m.component(Component, {}, "X")
ok 18 <Component id="test"/> -> m.component(Component, {id:"test"})
ok 19 <Component id="test">X</Component> -> m.component(Component, {id:"test"}, "X")
ok 20 <Component id="test">X{X} X {X}</Component> -> m.component(Component, {id:"test"}, "X", X, " X ", X)
@lhorie what do you think about these, particularly 17 (no attributes, children) and 20 (multiple children) ? I don't have a feel for what will and won't work in terms of passing children to Mithril components.
My assumption is that if you needed to pass both an args/options object and some child contents to a component, your view signature would end up something like this (rather than forcing children into an array - which is another option).
view(ctrl, args, ...children)
On 17, if you wanted to implement a component which optionally took args/options and children, you'd have to start checking arguments passed to view
to determine which was which - forcing an empty arguments object in the case of a tag which has no attributes but has children is currently just an opinion based on a hunch.
from msx.
I'd say make 17 output m.component(Component, {}, ["X"])
and 20 output m.component(Component, {id:"test"}, ["X", X, " X ", X])
.
Unlike m()
, m.component
does not have a comp, ...children
overload (with attrs omitted), and the view always receives attributes as the second parameter. The rationale for this is to avoid creating boilerplate for handling multiple overloads.
Components do allow unlimited number of arguments, but I think sticking to m.component(Component, AttrObject, ChildrenArray)
is preferable because it caters to the simplest way to handle children in the component (i.e. no arguments
splicing required)
It's a bit unfortunate that the HTML syntax doesn't leave room for us to disambiguate between ["X"]
and "X"
, so I think the best thing to do is assume the most common/flexible case.
from msx.
Related Issues (17)
- Add precompile HOT 3
- missing comma in options HOT 1
- How to use config callbacks? HOT 1
- Is there a JSX equivalent to this.props.children? HOT 4
- Typescript JSX support HOT 1
- absolute path for output
- Parameters and variables HOT 1
- not support void tag,must be self-closed;
- svg foreignObject tag is not supported HOT 2
- How does this play with Facebook-react patent licensing?
- Rewrite support HOT 3
- Rendering of false HOT 2
- Optimizing use of the cache HOT 1
- Upgrade to JSX Transformer 0.12 HOT 1
- Publish latest changes to npm HOT 1
- How to compile .html files?
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 msx.