effector-storage
effector-storage copied to clipboard
Handle `pickup` events from the past
This is more like an idea, I don't know is it really possible yet.
Maybe it would be useful for persist
to react on pickup
event from the past?
Like in this example:
const pickup = createEvent()
// create `persist` beforehand
const persist = createPersist({ pickup })
// trigger `pickup` on application start
allSettled(pickup, { scope })
// after some time, use created `persist`, and it will pick up value right away and in the correct scope,
// because `pickup` event was already triggered after `createPersist` call
persist({ store, key })
Currently createPersist
no more than just carrying arguments, and this code will do nothing, because persist
starts listening on pickup
only upon calling persist
, and not when createPersist
is called.
After some time of consideration and playing around few concepts, I started to think this is hardly possible technically...
For example, there are three scopes, and pickup
was called 3 times (one trigger per one scope). Then persist
call should somehow determine, which of those 3 triggers should be used. For now I cannot think of any way to do it.