Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax strict mode, solves #798, #563 #812

Merged
merged 14 commits into from
Feb 3, 2017

Conversation

mweststrate
Copy link
Member

Excerpt from changelog:


Strict mode has been relaxed a bit in this release. Also computed values can now better handle creating new observables (in an action if needed). The semantics are now as follows:

  • In strict mode, it is not allowed to modify state that is already being observed by some reaction.
  • It is allowed to create and modify observable values in computed blocks, as long as they are not observed yet.

In order words: Observables that are not in use anywhere yet, are not protected by MobX strict mode.
This is fine as the main goal of strict mode is to avoid kicking of reactions at undesired places.
Also strict mode enforces batched mutations of observables (through action).
However, for unobserved observables this is not relevant; they won't kick of reactions at all.

This fixes some uses cases where one now have to jump through hoops like:

  • Creating observables in computed properties was fine already, but threw if this was done with the aid of an action. See issue #798.
  • In strict mode, it was not possible to update observable values without wrapping the code in runInAction or action. See issue #563

Note that the following constructions are still anti patterns, although MobX won't throw anymore on them:

  • Changing unobserved, but not just created observables in a computed value
  • Invoke actions in computed values. Use reactions like autorun or reaction instead.

Note that observables that are not in use by a reaction, but that have .observe listeners attached, do not count towards being observed.
Observe and intercept callbacks are concepts that do not relate to strict mode, actions or transactions.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 96.223% when pulling 333398b on fix/798-invoke-action-from-computed into 34a1b94 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 96.223% when pulling 333398b on fix/798-invoke-action-from-computed into 34a1b94 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants