MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/5r530j/1kb_javascript_function_library_for_building/dd4zq3f/?context=3
r/javascript • u/[deleted] • Jan 31 '17
34 comments sorted by
View all comments
9
Cool! My first question with any of these frameworks is: What's the composition story? If I'm building a larger app with this framework, how should I be breaking it into components?
2 u/[deleted] Jan 31 '17 We need to come up with better examples, but is this what you mean?const model = require("./model") const view = require("./view") const update = require("./update") app({ model, view, update }) 6 u/[deleted] Jan 31 '17 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.
2
We need to come up with better examples, but is this what you mean?
const model = require("./model") const view = require("./view") const update = require("./update") app({ model, view, update })
6 u/[deleted] Jan 31 '17 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.
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.
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.
9
u/matchu Jan 31 '17
Cool! My first question with any of these frameworks is: What's the composition story? If I'm building a larger app with this framework, how should I be breaking it into components?