Skip to content

Commit

Permalink
fix for 2135
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergonz committed Oct 4, 2019
1 parent 281dcd8 commit e15be68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/core/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import {
} from "../internal"
import { allowStateReadsStart, allowStateReadsEnd } from "./derivation"

// we don't use globalState for these in order to avoid possible issues with multiple
// mobx versions
let currentActionId = 0
let nextActionId = 1

export interface IAction {
isMobxAction: boolean
}
Expand Down Expand Up @@ -78,18 +83,18 @@ export function _startAction(actionName: string, scope: any, args?: IArguments):
prevAllowStateReads,
notifySpy,
startTime,
actionId: globalState.nextActionId++,
parentActionId: globalState.currentActionId
actionId: nextActionId++,
parentActionId: currentActionId
}
globalState.currentActionId = runInfo.actionId
currentActionId = runInfo.actionId
return runInfo
}

export function _endAction(runInfo: IActionRunInfo) {
if (globalState.currentActionId !== runInfo.actionId) {
if (currentActionId !== runInfo.actionId) {
fail("invalid action stack. did you forget to finish an action?")
}
globalState.currentActionId = runInfo.parentActionId
currentActionId = runInfo.parentActionId

if (runInfo.error !== undefined) {
globalState.suppressReactionErrors = true
Expand Down
10 changes: 0 additions & 10 deletions src/core/globalstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,6 @@ export class MobXGlobals {
* they are not the cause, see: https://github.com/mobxjs/mobx/issues/1836
*/
suppressReactionErrors = false

/*
* Current action id.
*/
currentActionId = 0

/*
* Next action id.
*/
nextActionId = 1
}

let canMergeGlobalState = true
Expand Down

0 comments on commit e15be68

Please sign in to comment.