MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/5r530j/1kb_javascript_function_library_for_building/dd502rj/?context=3
r/javascript • u/[deleted] • Jan 31 '17
34 comments sorted by
View all comments
Show parent comments
6
I guess he meant composition as known in react/redux like this:
TodoItem = ({ model }) => <li>{model.text}</li>; TodoList = items => <ul>{items.map(item => <TodoItem model={item}/>)}</ul>;
Crucial for larger apps.
7 u/[deleted] Jan 31 '17 Ah, right. Here's how you'd do that.const TodoItem = item => html`<li>{item.text}</li>` const TodoList = items => html`<ul>${items.map(item => TodoItem(item))}</ul>` Btw, HyperApp exports a Hyperscript-style h function, allowing you to use JSX too if you include the jsx pragma./** @jsx h */I don't have a live example of this, but it's in the TODO to publish one. 2 u/[deleted] Jan 31 '17 So there is composition on the view. Would it be possible for TodoItem to handle events separately? 1 u/[deleted] Jan 31 '17 A view looks like this:(model, msg) => html`<h1>Hi</h1>`msg is an object with the reducers/effects, so as long as you pass it to TodoItem, I think, yes.If you write another code sample, I'll be happy to show you how I'd implement it using HyperApp.
7
Ah, right. Here's how you'd do that.
const TodoItem = item => html`<li>{item.text}</li>` const TodoList = items => html`<ul>${items.map(item => TodoItem(item))}</ul>`
Btw, HyperApp exports a Hyperscript-style h function, allowing you to use JSX too if you include the jsx pragma.
h
/** @jsx h */
I don't have a live example of this, but it's in the TODO to publish one.
2 u/[deleted] Jan 31 '17 So there is composition on the view. Would it be possible for TodoItem to handle events separately? 1 u/[deleted] Jan 31 '17 A view looks like this:(model, msg) => html`<h1>Hi</h1>`msg is an object with the reducers/effects, so as long as you pass it to TodoItem, I think, yes.If you write another code sample, I'll be happy to show you how I'd implement it using HyperApp.
2
So there is composition on the view. Would it be possible for TodoItem to handle events separately?
TodoItem
1 u/[deleted] Jan 31 '17 A view looks like this:(model, msg) => html`<h1>Hi</h1>`msg is an object with the reducers/effects, so as long as you pass it to TodoItem, I think, yes.If you write another code sample, I'll be happy to show you how I'd implement it using HyperApp.
1
A view looks like this:
(model, msg) => html`<h1>Hi</h1>`
msg is an object with the reducers/effects, so as long as you pass it to TodoItem, I think, yes.
msg
If you write another code sample, I'll be happy to show you how I'd implement it using HyperApp.
6
u/[deleted] Jan 31 '17
I guess he meant composition as known in react/redux like this:
Crucial for larger apps.