Skip to content

Commit

Permalink
Revert "Alternative solution"
Browse files Browse the repository at this point in the history
This reverts commit e15bc78.
  • Loading branch information
xaviergonz committed Sep 24, 2018
1 parent 4808b29 commit 84b4cd2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
11 changes: 10 additions & 1 deletion src/core/derivation.ts
Expand Up @@ -135,8 +135,17 @@ export function isComputingDerivation() {
}

export function checkIfStateModificationsAreAllowed(atom: IAtom) {
const hasObservers = atom.observers.size > 0
// Should never be possible to change an observed observable from inside computed, see #798
if (globalState.computationDepth > 0 && hasObservers)
fail(
process.env.NODE_ENV !== "production" &&
`Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: ${
atom.name
}`
)
// Should not be possible to change observed state outside strict mode, except during initialization, see #563
if (!globalState.allowStateChanges && (atom.observers.size > 0 || globalState.enforceActions === "strict"))
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "strict"))
fail(
process.env.NODE_ENV !== "production" &&
(globalState.enforceActions
Expand Down
24 changes: 0 additions & 24 deletions test/base/action.js
Expand Up @@ -202,30 +202,6 @@ test("should be possible to change observed state in an action called from compu
d()
})

test("should be possible to change observed state in an action called from computed if run inside _allowStateChangesInsideComputed - 2", () => {
const a = mobx.observable.box(2)
const d = mobx.autorun(() => {
a.get()
})

const testAction = mobx.action(() => {
a.set(3)
})

const c = mobx.computed(() => {
mobx._allowStateChanges(true, () => {
testAction()
})
return a.get()
})

c.get()

mobx._resetGlobalState()
d()
})


test("should not be possible to change observed state in an action called from computed", () => {
var a = mobx.observable.box(2)
var d = mobx.autorun(() => {
Expand Down

0 comments on commit 84b4cd2

Please sign in to comment.