Replies: 3 comments
-
What method should do if user changed structure of the shape? const $user = shape({ name: $name, surname: $surname })
$user.on(event, (_, ()) => ({ anything: true })) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think the same way that spread works - just skip updates on the stores that was not passed. But that could be a type error as well |
Beta Was this translation helpful? Give feedback.
0 replies
-
@Kelin2025 I think you gave an unrealistic example const userLoaded = createEvent()
const $user = restore({name: '', surname: ''}, userLoaded)
const $name = $user.map(({name}) => name)
const $surname = $user.map(({surname}) => surname)
// Easily attach reset on $user store
$user.reset(sessionCleared) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
There's a lot of cases like this:
You have some state object which you split into atomic stores, then combine into a single store to use somewhere you need
But the problem comes when you have something like
userLoaded
event - you can't mutate combined storeSo you either write a bunch of
.on
or usepatronum/spread
:Still feels like a lot of boilerplate
In community, there's also a lot of questions like "how can I reset combined store", "I tried to do $user.on but it does not work" etc. Which means it's a common case
Solution
Would be cool to have
shape
utility which creates combine-like store but supports mutationsWhy not extending
combine
It might create a lot of confusing for users, because extending
combine
will cause inconsistency:combined
store with object is mutablecombined
store with function is immutableBeta Was this translation helpful? Give feedback.
All reactions