effector-storage icon indicating copy to clipboard operation
effector-storage copied to clipboard

Handle `pickup` events from the past

Open yumauri opened this issue 1 year ago • 1 comments

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.

yumauri avatar Dec 28 '23 16:12 yumauri

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.

yumauri avatar Jan 18 '24 09:01 yumauri