Allow mixins to export a view and remove render event.
See original GitHub issueMixins can extend your app’s state, actions and events. Take it one step further and let them export a view
function too.
A mixin’s view would work by returning an object of one or more components.
// mixin
view(state, actions) {
return {
MyComponent,
MyOtherComponent
}
}
While the state, actions and events props are plain objects that we can merge for you, we can’t merge views as they are functions! But we can collect the views into an object and give it to you.
// app
view(state, actions, { MyComponent }) {
return <MyComponent />
}
This can be useful for components that work together with a mixin like the Router/Link.
This means instead of e.g., myLibrary.Hello
component and myLibrary.hello
mixin, now you could do this instead.
export default function() {
return {
state: {
hello: {
color: "red"
}
},
actions: {
hello: {
doSomething() { /* ... */ }
}
},
view(state, actions) {
return {
hello: {
Hello(props, children) {
// This is a regular component.
// What's special about it is that's inside the view closure, so
// it's effectively "pre-wired" to the state and actions.
return (
<a
style={{ color: state.hello.color }}
href={props.url}
onclick={actions.hello.doSomething}
>
{children}
</a>
)
}
}
}
}
}
}
Then you can then use it like this.
import hello from "hyperapp-hello"
app({
view: (state, actions, { hello: { Hello } }) => (
<div class="myapp">
<Hello url="https://hyperapp.js.org" />
</div>
),
mixins: [hello()]
})
Your comments and questions please. 👋
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (12 by maintainers)
Top Results From Across the Web
Mixin for destroyed Vue component is still listening for events
In the parent component when I toggle the rendering by changing the isSearchingInFolders variable the expected component is destroyed and ...
Read more >Developing Widgets | vtk.js - Kitware, Inc.
Removing a widget from a view is done by widgetManager. ... This allows to render complex widgets by using multiple simple and reusable...
Read more >Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >Using mixins with class-based views - Django documentation
Let's look at how two of Django's generic class-based views are built out of mixins providing discrete functionality. We'll consider DetailView , which ......
Read more >Mixins - Vue.js
Mixins are a flexible way to distribute reusable functionalities for Vue components. A mixin object can contain any component options. When a component...
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
@zaceno This was from here: https://hyperapp.slack.com/archives/C41ECC0V6/p1505964096000002
@JorgeBucaran oh ya I can adapt my router, I’m just asking mainly out of curiosity if there are other use-cases where it couldn’t be replicated with the view exported from mixin. I can’t think of a use myself outside of routing.