Hey there,
first of all: thanks for the lib, I love it!
I'm using the store in a plain class that reacts to store updates and on update I want to execute async code and update the store.
Usually one would do that with a reaction:
this.storeSubscription = MyStore.createReaction(
(s) => s.someAttribute,
(watched, draft, original, lastWatched) => { <some code> }
)
As we cannot have awaits in the reaction function, the async code is in a class method async doAsyncStuff(watched, draft, original, lastWatched). Thus I'd like to bind it:
this.storeSubscription = MyStore.createReaction(
(s) => s.someAttribute,
this.doAsyncStuff.bind(this)
)
However this fails with an immer exception: [Error] Unhandled Promise Rejection: Error: [Immer] produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '[object Promise]'.
Is there a way to use the reactions with async functions?
Hey there,
first of all: thanks for the lib, I love it!
I'm using the store in a plain class that reacts to store updates and on update I want to execute async code and update the store.
Usually one would do that with a reaction:
As we cannot have awaits in the reaction function, the async code is in a class method
async doAsyncStuff(watched, draft, original, lastWatched). Thus I'd like to bind it:However this fails with an
immerexception:[Error] Unhandled Promise Rejection: Error: [Immer] produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '[object Promise]'.Is there a way to use the reactions with async functions?