I would like to amend this: don't use Redux until you have problems with vanilla React. - Dan Abramov
Dan said this way back in 2016, and now th...
For further actions, you may consider blocking this person and/or reporting abuse
Hello, look at the Meiosis pattern.
Regards
Search Meiosis on Dev to
First time I hear about it: dev.to/artydev/frontend-state-mana...
The explanations are terse, but yes I saw this:
meiosis.js.org/
"Think Redux, MobX, Cerebral, React Context, etc. but without having library imports everywhere and being tied to a framework API. Instead, just plain functions and objects. All you need is a simple stream library such as Flyd or Mithril Stream"
So you don't need to have library imports ... but you do need a library ;)
No :-)
All you need is two streams functions map and scan that you can implement yourself or use the simple implementation mithril-stream
And the function I use to merge states is a thirty lines of code called mergerino, which extends Object.assign.
I would not call them library, they are so tiny and very specialised
You can use whathever you want for the view (event document.innerHTML)
Here I use JQuery
MeiosisJS
Look at this for a starting pont :
observables
Regards
code for mergerino
the code of mithril-stream is here from Isiah Meadows Mithril's maintener.
So you need to learn how think in terms of streams and observables (I think RxJS is a famous library in this area) ... if you're not familiar with that paradigm yet then it's definitely a learning curve compared to the way you'd normally do things with Redux or Context.
Think of streams as Excel cells and you will have a good starting point.
I have written a few lines as introduction here
streams
You absolutely don't need RxJS, as I said earlier you only need map and scan for Meiosis
Here is very simple stream implementaion with a map function :
You can test it here :
StreamMap
Regards
Good explanation, but I can't help but notice how similar the code looks compared to what you would write if you use Redux - you still write reducers, actions, dispatch, etcetera ... so, I could be wrong, but at first sight we don't seem to have gained much in terms of reducing boilerplate.
The only simplification then seems to be that we can omit one or two dependencies from our package.json (but Redux doesn't add that much to the bundle size, it's a pretty small library).
Note that I'm not saying that this approach (Context) is worse than using Redux, but I also don't see immediately how it's better or simpler - the way you manage state with Context is largely the same.
Or am I missing something?
You are right. I never considered "reducing boilerplate" as a goal. I wanted to show that we can achieve redux like functionality in vanilla react itself.
Understood ... but look at this one - we might not need Redux, but we might even also not need Context! dev.to/g_abud/why-i-quit-redux-1knl
Sure will check it outβπ½
Really nice introduction to Context. Is there a well-established way to use asynchronous actions, similar to redux thunk?
You can declare an async function in the value prop to the Provider. Here's an example: codesandbox
P.S. Not sure if this exactly what you asked for.
Yes, this is it. It occurred to me when I saw the example that I don't need middleware to access state - here I can simply refer to it if I need for example some intersection between fetched data and current state.
Thank you :-)
You're welcomeππ½
It was! Thanks mate :)
Glad you liked it.