Make view easier to use in modules?
See original GitHub issueI’m bringing #294 back from the dead!
Now that we have state slice and modules, I thought it was kinda awkward module views are hard to use.
Introducing views!
https://gist.github.com/Pyrolistical/f3a4b1577741dd847aef73300f8f11c3
(I didn’t re-cap the demo, but you can run the new code yourself it works like this!)
I wrote a HoA withViews
and added a views
parameter to the view
function. This allows us to write stuff like
withViews(app)({
view(state, actions, {left, right}) {
return <main>
<left name="Left" />
<right name="Right" />
<p>Sum {state.left.count + state.right.count}</p>
</main>
},
modules: {
left: counter,
right: counter,
}
}, document.getElementById('app-entry'))
where counter
is just a module
const counter = {
state: {
count: 0
},
view(state, actions, views) {
return <div>
<h1>{state.name} {state.count}</h1>
<button onclick={actions.down} disabled={state.count <= 0}>-</button>
<button onclick={actions.up}>+</button>
</div>
},
actions: {
down(state) {
return {
count: state.count - 1
}
},
up(state) {
return {
count: state.count + 1
}
}
}
}
I feel this is a missing piece to the modules story. Should we integrate this into the core or leave this as a HoA? You can see the source for withViews: https://gist.github.com/Pyrolistical/f3a4b1577741dd847aef73300f8f11c3#file-index-html-L83
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (18 by maintainers)
Top Results From Across the Web
Create a simple block view | Views module - Drupal
Views allows you to create listings of data on your site as blocks which can be placed in regions on your site.
Read more >Filters and views in modules - IBM
Module views are a subset of the module content. It is a simple way to filter out content from the module and helps...
Read more >Common modularization patterns - Android Developers
This page gives an overview of some general rules and common patterns that you can employ when developing multi module Android apps.
Read more >Angular Modules Best Practices 2021 - Chris Kohler
How to decide what pattern to use? ... The easiest decision is to rule out putting everything into one single module. If the...
Read more >Using Modules to Organize Course Content
Structuring your course with Modules can also make it easier for you to quickly see how students are progressing through the content and ......
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
The way I see it, this sort of module views are basically the same as getters/computeds The only thing is that they return a vtree rather than a number or string. (And a “traditional” getter only needs access to the state, not actions, I suppose) My point being: rather than having support for something named “views” specifically, I’d rather have support for general getters, and we can use getters for “pre-wired views” as well as other things.
@JorgeBucaran here are the goods, i appended to the gist.
I ran into #437 and #438, so I included #426 at the end of the gist to get around it.
(1) (easy) add a button to the main view that adds +1 to both left and right
(2) (hard) a button that adds a new counter, so no more right or left, but a collection of counters.
many
module, which takes in a module and allows you to add moreusage looks like:
the view looks like:
where
counters
is the fromviews