Comments (5)
I also encountered 2. while playing with overmind and that's what made me explore some alternative way to express actions (that and the type of parallele 😄 ) (https://github.com/etienne-dldc/meleze-store).
To be more specific I was doing some pattern matching (branch) and dealing with null value was just not practical... it feels like the declarativeness, while great for the most part, was holding me back.
Note: As I said before, I'm not proposing to change overmind's API, I'm just sharing my ideas in case it helps :)
So once I realized that I was not happy with the code I was writing I thought about how I could make it better. The answer I found was that the code I was having a hard time expressing declaratively should be written imperatively, with plain old Javascript !
You might say that RFC above solve my problem, and in a way it does. But what made me thing about a different system is that the action
above is basically an opt out button, once you are in an action (aka imperative mode) you can't really go back to declarative, your only way is by returning an value but then it feels a bit out of order...
So how did I solve this ? By using the return value as the next thing to do.
Basically instead of building a function, I'm building an object (called an executable) that can be executed.
So const setFoo = mutate(({ state }) => { state.foo = 'bar' })
return an object that contain the mutation function.
Then you have an action()
executable factory that take as parameter a function that must return an executable:
const maybeSetFoo = action(({ value }) => {
if (value > 42) {
// we return the mutation we want to perform
return setFoo;
}
// null is ignored
return null;
})
Here I could have used a filter
but for more complex use case and things like type guards it's just not practical to use declarative code.
If you want to see what it looks like you can take a look here (still very WIP) : https://github.com/etienne-dldc/meleze-store/blob/master/src/index.ts
from overmind.
@christianalfoni Is this a thought experiment or does the implementation live somewhere we can play with?
from overmind.
@etienne-dldc Thanks for your input here! I see where you are going and yeah, that is certainly powerful! And I guess there is nothing wrong with us creating an operator that does exactly that. Instead of like when
which returns a boolean, you return an actual operator. Though not sure about typing etc, which I guess you worked a lot on? :)
One thing I see though is that even though the implementation has a lot of power, it will hide some implementation details in the expressed pipe.
pipe(
maybeSetFoo // You do not know what operator is actually run when truthy
)
pipe(
when(valueIsMoreThan42, {
true: setFoo,
false: null
})
)
This was of course a contrived example as well and splitting up into a when
etc. is exactly where you start doing quite some additional work, as you point out. It is a difficult one and really nice to have both options POC-ed :)
from overmind.
@abalmos It is a tiny change I will do later today a long with a couple of other small fixes... which marks that my list of fixes is done and I can focus on more docs and start preparing some videos :)
from overmind.
Old stuff
from overmind.
Related Issues (20)
- Is there any way to change states outside component? HOT 10
- [BUG] State mutation error HOT 3
- Svelte + Overmind : Function called outside component initialization
- [BUG] Statemachine errors on send(), possible documentation issue HOT 2
- Devtools: add the option to fail silently if port wasn't found HOT 2
- [BUG] Vue State Hooks loses reactivity once using in nested components. HOT 4
- [BUG] States changes are not reflecting in the UI but dev tool shows the value changed HOT 1
- [BUG] Typo in "ensureMutationTrackingIsEnabled" function HOT 3
- Error: While trying to resolve module `phoenix` HOT 1
- [BUG] TypeError with webpack 5 HOT 1
- [BUG] proxy-state-tree - You are mutating the path HOT 1
- Does the graphql package work with any subscriptions on a graphql server or is it specific to the phoenix framework?
- [BUG] svelte reactivity broken on subsequent state changes cross-components HOT 4
- [Question] Is the project dead? Is so, what are options to migrate to? HOT 5
- [BUG] Incompatible with React 18 with Strict Mode HOT 13
- Page doesn't re-render after navigation in Next 13 HOT 12
- [BUG] `overmind-react` - multiple overmind named instances HOT 1
- [BUG] Overmind JS Not working in Next JS 13 HOT 1
- [BUG] Usage of 'useSyncExternalStore' causes errors with react below version 18 HOT 3
- [BUG] Can't mock overmind for jest snapshots HOT 1
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 overmind.