Comments (18)
Vuex (Vue.js equivalent to msg
) also uses a flat structure. The reasoning is, as far as I understand it, that there is no practical benefit to namespacing/nesting over simply prefixing as a strategy to avoid naming collisions.
That said, I also am curious about strategies (in general -- not just for the reducers/effects) for structuring and sensibly managing larger scale, complex apps (with potentially hundreds of reducers). All my experience with really big and complex apps is from the world of MVC, and in coming to this brave new world of the Elm-ish/React-ish paradigm, I have mostly been exposed to trivial examples and haven't found much in terms of composing larger apps from smaller pieces (like a SAM equivalent of H(ierarchical)MVC for example).
from hyperapp.
const red = require("./red-effects")
const blue = require("./blue-effects")
const yellow = require("./yellow-effects")
app({
update: { red, blue, yellow }
})
Now there is no naming conflict but it is no longer flat 🤔
from hyperapp.
@selfup This is possible though:
app({
update: {
...red,
...blue,
...yellow
}
})
from hyperapp.
@jbucaran it makes, but there may be name collisions... That's the important thing.
from hyperapp.
choo solved this with namespaces IIRC.
I didn't like the idea of namespaces, so I didn't implement any.
What other options do we have?
from hyperapp.
@tunnckoCore We can talk about combining this with the solution for multiple models/components/etc. though.
from hyperapp.
Forgot to close here. This has been implemented by @dodekeract and it's available from 0.6.0 🎉!
Now, reducers and effects, can be used as usual or instead of a single object with functions, can also have arbitrarily nested objects with more functions. These functions can be on the same level as the namespace or above, or under. It's recursive in nature, so you can go crazy with this.
The object that holds all this data,actions
is initialized only once, so there is no fear of this slowing us down, in fact, after this HyperApp became faster. From 1.40 down to 1.37.
See #75.
/cc @nichoth
from hyperapp.
@dodekeract Interesting. Nope. I never considered this.
Sometimes because it's nice to have doesn't mean we should have it, but I am open to feedback.
from hyperapp.
Don't see value. It is better to be flat. But any use case, more real examples?
from hyperapp.
@tunnckoCore basically anything with lots of updates/effects. That way it'd be possible to split it into multiple files. It's also less tedious to prevent name clashes and easier to remember the names.
from hyperapp.
const red = require("./red-effects")
const blue = require("./blue-effects")
const yellow = require("./yellow-effects")
app({
update: Object.assign({}, red, blue, yellow)
})
Does that make sense?
from hyperapp.
choo solved this with namespaces IIRC.
Yes and no. Not exactly, or at least I think that they have the same problem in that case. There namespaces are for different models. Here we talk for one model.
from hyperapp.
@zaceno same here :) I was MVC a long ago, but still can get the Components thing really enough. But also don't have enough time and wish to review some big project using vue, react or whatever.
As about ELM-sh.. I really feel it easy and like it. Thanks to choo for very good README and intro to all that.
from hyperapp.
@dodekeract Ohh that is nice too
But then i wonder what happens if the same keys are present...which one does it call?
from hyperapp.
@selfup the last one. In this case the one from yellow
.
from hyperapp.
Oh interesting! Good to know there is a fallback
from hyperapp.
Closing as I don't think I'll be implementing nested actions.
from hyperapp.
I ended up using the same nested interface in my project also to compose components, seems pretty good so far.
from hyperapp.
Related Issues (20)
- JSX fails if no props are given HOT 6
- A way to insert raw Html HOT 1
- TypeError: can't access property 0, newSubs is null, when setting the state to undefined. HOT 4
- Issue with null-vnodes HOT 1
- prevent rerender node HOT 2
- The dispatch initializer ends in an endless loop on init when dispatching any action HOT 7
- Injected classes gets removed when using object/array to define class props HOT 1
- hyperapp version HOT 3
- Memo Data Gotcha HOT 5
- Confusing doc for actions -> wrapped actions HOT 5
- Passing arguments to init HOT 4
- [Question] Headless mode is still possible? HOT 1
- Destroying a child app HOT 8
- @hyperapp/html: use a Proxy? HOT 9
- Actions returning other Actions HOT 5
- Compile template tag to hyperscript HOT 17
- A challenge to hyperapp community HOT 1
- Has 2.0 been dropped from development? HOT 3
- oldSub[2] is not a function HOT 3
- Cannot read properties of null (reading 'length') HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hyperapp.