mobx6: Dynamic action
#2651
-
I have helper method that generating typical methods for some actions: for example:
and even marks it explicitly as action in
generateLoadList returns action( ) wrapper:
but have warning in console:
it was working fine in mobx5, what is the right way to migrate it to 6? |
Beta Was this translation helpful? Give feedback.
Answered by
kubk
Nov 30, 2020
Replies: 2 comments
-
You can either disable action enforcing by setting if (store[loadFlag]) return
store[loadFlag] = true
try {
const result = await loaderFn(options);
runInAction(() => {
store[targetProp].replace(result)
})
return true
}
catch (e) {
store.setError( name, extractErrorMessage(e) )
}
finally {
runInAction(() => {
store[loadFlag] = false
})
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mogadanez
-
For more details, see https://mobx.js.org/actions.html#asynchronous-actions
…On Mon, Nov 30, 2020 at 9:11 AM kubk ***@***.***> wrote:
You can either disable action enforcing by setting "enforeActions":
"never" or wrap all observable assignments into action/runInAction:
if (store[loadFlag]) return
store[loadFlag] = true
try {
const result = await loaderFn(options);
runInAction(() => {
store[targetProp].replace(result)
})
return true
}
catch (e) {
store.setError( name, extractErrorMessage(e) )
}
finally {
runInAction(() => {
store[loadFlag] = false
})
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2651 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBF64US2L7UYFMGRXKDSSNOTNANCNFSM4UG2K4NA>
.
|
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
You can either disable action enforcing by setting
"enforeActions": "never"
or wrap all observable assignments intoaction/runInAction
: