Skip to content

Commit

Permalink
moved transaction from core to api
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 2, 2017
1 parent ca734ad commit ab0b591
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
13 changes: 2 additions & 11 deletions src/core/transaction.ts → src/api/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {startBatch, endBatch} from "./observable";
import {deprecated} from "../utils/utils";
import {untrackedStart, untrackedEnd} from "./derivation";
import {executeAction} from "../core/action";

/**
* @deprecated
Expand All @@ -18,13 +17,5 @@ export function transaction<T>(action: () => T, thisArg = undefined): T {
}

export function runInTransaction<T>(action: () => T, thisArg = undefined): T {
// TODO: use execute action!
startBatch();
const prev = untrackedStart();
try {
return action.call(thisArg);
} finally {
untrackedEnd(prev);
endBatch();
}
return executeAction("", action);
}
2 changes: 1 addition & 1 deletion src/core/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function startAction(actionName: string, fn: Function, scope: any, args?: IArgum
// actions should not be called from computeds. check only works if the computed is actively observed, but that is fine enough as heuristic
invariant(!isComputedValue(globalState.trackingDerivation), "Computed values or transformers should not invoke actions or trigger other side effects");

const notifySpy = isSpyEnabled();
const notifySpy = isSpyEnabled() && !!actionName;
let startTime: number = 0;
if (notifySpy) {
startTime = Date.now();
Expand Down
2 changes: 1 addition & 1 deletion src/mobx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export { Reaction, IReactionPublic } from "./core/rea
export { IDerivation, untracked, IDerivationState } from "./core/derivation";
export { useStrict, isStrictModeEnabled } from "./core/action";
export { spy } from "./core/spy";
export { transaction } from "./core/transaction";
export { IComputedValue } from "./core/computedvalue";

export { asReference, asFlat, asStructure, asMap } from "./types/modifiers-old";
Expand All @@ -38,6 +37,7 @@ export { /* 3.0: IValueDidChange, */ IValueWillChange, IObservableValue } from "
export { IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice, isObservableArray } from "./types/observablearray";
export { IKeyValueMap, ObservableMap, IMapEntries, IMapEntry, IMapWillChange, IMapChange, isObservableMap, map, IObservableMapInitialValues, IMap } from "./types/observablemap"

export { transaction } from "./api/transaction";
export { observable, IObservableFactory, IObservableFactories } from "./api/observable";
export { computed, IComputed, IComputedValueOptions } from "./api/computed";
export { isObservable } from "./api/isobservable";
Expand Down
2 changes: 1 addition & 1 deletion src/types/observablemap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {IEnhancer, deepEnhancer} from "./modifiers";
import {runInTransaction} from "../core/transaction";
import {untracked} from "../core/derivation";
import {allowStateChanges} from "../core/action";
import {IObservableArray, ObservableArray} from "./observablearray";
Expand All @@ -10,6 +9,7 @@ import {IListenable, registerListener, hasListeners, notifyListeners} from "./li
import {isSpyEnabled, spyReportStart, spyReportEnd} from "../core/spy";
import {arrayAsIterator, declareIterator, Iterator} from "../utils/iterable";
import {observable} from "../api/observable";
import {runInTransaction} from "../api/transaction";
import {referenceEnhancer} from "./modifiers";

/**
Expand Down
1 change: 1 addition & 0 deletions test/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ test('should not be possible to invoke action in a computed block', t => {
t.throws(() => {
mobx.autorun(() => c.get());
}, /Computed values or transformers should not invoke actions or trigger other side effects/, 'expected throw');
mobx.extras.resetGlobalState();
t.end();
});

Expand Down

0 comments on commit ab0b591

Please sign in to comment.