Components
See original GitHub issueLet’s discuss how components could look like in a future version of HyperApp.
Submitted Proposals
- https://gist.github.com/zaceno/83286dfd2a18ebbd3b4f1d7cb5810a0c via @zaceno
- https://gist.github.com/Swizz/8437df6ac5ec4985e72e648d242f6a9f via @Swizz
Example
counter.js
const Counter = (props, children) => ({
state: {
value: props.value
},
view: ({ value }, { inc, dec }) =>
<div>
<h1>{state.value}</h1>
<button onclick={inc}>+</button>
<button onclick={dec}>-</button>
</div>,
actions: {
inc: state => state + 1,
dec: state => state - 1
}
})
index.js
app({
state: {
title: "Hello."
},
view: (state, actions) =>
<main>
<h1>{state.title}</h1>
<Counter value={1} />
</main>
})
Credits
All credit goes to @MatejMazur:
Related
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:171 (117 by maintainers)
Top Results From Across the Web
Component Definition & Meaning - Merriam-Webster
The meaning of COMPONENT is a constituent part : ingredient. How to use component in a sentence. Synonym Discussion of Component.
Read more >Component - Definition, Meaning & Synonyms - Vocabulary.com
Technically speaking, a component is an element of a system or a part of a machine. But a component can also be a...
Read more >Component Definition & Meaning - Dictionary.com
being or serving as an element (in something larger); composing; constituent: the component parts of a computer system. QUIZ. WILL YOU SAIL OR...
Read more >COMPONENT | definition in the Cambridge English Dictionary
one of the parts of a system, process, or machine: Fair pay for child-care providers is a vital component of welfare reform.
Read more >41 Synonyms & Antonyms for COMPONENTS - Thesaurus.com
Find 41 ways to say COMPONENTS, along with antonyms, related words, and example sentences at Thesaurus.com, the world's most trusted free thesaurus.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am having mixed feelings about components and I am not even sure we should add a new core concept to the framework. I am not even sure we even have a problem. I say, let’s build one or two cool apps first and then revisit this issue. 🤔😅😎
Now, I’m still interested to see @naugtur’s #245’s final form and the door is open to anyone who wants to add more to this discussion.
I am glad this conversation happened, though, because it motivated me to revisit hyperapp core values and I can confidently say I like it now more than ever.
To summarize my feelings about components:
But nothing is lost. On the contrary, we’ve gained the insight that there exist patterns that can help you create complex applications without losing the benefits of a single state tree.
Patterns
Widgets
@zaceno’s state/action bound custom tags is interesting and could be published as an independent module. I like to think of them as “widgets”. 🤓
See: https://codepen.io/zaceno/pen/gRvWPx
Split-mixins
@MatejMazur’s Split-mixins is a clever trick that requires no changes to core and lets you use mixins to achieve something similar to stateful components.
Mixins
@Swizz Super-powered mixins.
See: https://github.com/hyperapp/hyperapp/issues/238#issuecomment-310999839.
Other
Final remarks
We’re all (I am!) on a learning curve and tyring to figure this out. I am sure more patterns will show up, so please share your research and findings.
Thank you all, for your feedback and such an epic thread! 💥 🎉🥇
@MatejMazur @Swizz @jamen @everyone
How does everyone feel about this approach?
app.js
counter.js