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

Fix for #2135 (mobx4) #2137

Merged
merged 1 commit into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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