Intended outcome:
Just like initializing an observable object or array, a map can be initialized outside an action.
Actual outcome:
A strict-mode error is thrown.
How to reproduce the issue:
https://codesandbox.io/s/mobx-map-strict-error-pf8ql
import { configure, observable } from 'mobx'
configure({
enforceActions: "always",
});
export const testMap = observable.map([
["item", "text"]
]);
Versions
MobX 4.15.4
That is correct, observables should only be created in actions in always
mode. Try 'observed' instead or wrap in (runIn)Action
On Thu, 6 Aug 2020, 23:43 Michael Best, notifications@github.com wrote:
Intended outcome:
Just like initializing an observable object or array, a map can be
initialized outside an action.Actual outcome:
A strict-mode error is thrown.
How to reproduce the issue:
https://codesandbox.io/s/gifted-meninsky-pf8ql?file=/index.js
import { configure, observable } from 'mobx'
configure({
enforceActions: "always",});
export const testMap = observable.map([
["item", "text"]]);Versions
MobX 4.15.4
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx/issues/2424, or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAN4NBCN3HMFD2J4GSUEAE3R7MWYBANCNFSM4PXBMNQA
.
@mweststrate I made a fix. I feel free to close that PR if it's now correct.
I has a question: why can the observable.array and observable.object be created now?
The fix is correct. The idea of "always" strict mode is that all state
updates and creations should be done from an action, since in the mobx
philosophy state updates and creation should always be done in response to
some event, and hence wrapped in action.
That observable array and object (and maps) creation doesn't error is
mostly to be not be too pedantic, but those should in principle happen
inside actions as well.
Op vr 7 aug. 2020 04:56 schreef Chen Gang notifications@github.com:
@mweststrate https://github.com/mweststrate I made a fix. I feel free
to close that PR if it's now correct.
I has a question: why can the observable.array and observable.object be
created?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx/issues/2424#issuecomment-670307776, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AAN4NBAKKWQYLKQSMKY2J4DR7N3QHANCNFSM4PXBMNQA
.
Fixed and released as 5.15.6 / 4.15.6. Thanks @moonball!