Skip to content

Commit

Permalink
Merge branch 'master' into extractMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate authored Jan 26, 2017
2 parents 7473ad5 + 67f8255 commit 6bb7674
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* MobX can now be compiled on windows as well! #772 by @madarauchiha #GoodnessSquad
* Added documentation on how Flow typings can be used, #766 by @wietsevenema
* Added support for `Symbol.toPrimitive()` and `valueOf()`, see #773 by @eladnava #GoodnessSquad
* Supressed an exception that was thrown when using the Chrome Developer tools to inspect arrays, see #752

Re-introduced _structural comparison_. Seems we couldn't part from it yet :). So the following things have been added:

Expand Down
43 changes: 21 additions & 22 deletions src/api/action.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import {invariant, addHiddenProp} from "../utils/utils";
import {createClassPropertyDecorator} from "../utils/decorators";
import {createAction, executeAction} from "../core/action";
import {createAction, executeAction, IAction} from "../core/action";
import {getMessage} from "../utils/messages";


export interface IActionFactory {
// nameless actions
<A1, R, T extends (a1: A1) => R>(fn: T): T;
<A1, A2, R, T extends (a1: A1, a2: A2) => R>(fn: T): T;
<A1, A2, A3, R, T extends (a1: A1, a2: A2, a3: A3) => R>(fn: T): T;
<A1, A2, A3, A4, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4) => R>(fn: T): T;
<A1, A2, A3, A4, A5, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R>(fn: T): T;
<A1, A2, A3, A4, A5, A6, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a6: A6) => R>(fn: T): T;
<A1, R, T extends (a1: A1) => R>(fn: T): T & IAction;
<A1, A2, R, T extends (a1: A1, a2: A2) => R>(fn: T): T & IAction;
<A1, A2, A3, R, T extends (a1: A1, a2: A2, a3: A3) => R>(fn: T): T & IAction;
<A1, A2, A3, A4, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4) => R>(fn: T): T & IAction;
<A1, A2, A3, A4, A5, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R>(fn: T): T & IAction;
<A1, A2, A3, A4, A5, A6, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a6: A6) => R>(fn: T): T & IAction;

// named actions
<A1, R, T extends (a1: A1) => R>(name: string, fn: T): T;
<A1, A2, R, T extends (a1: A1, a2: A2) => R>(name: string, fn: T): T;
<A1, A2, A3, R, T extends (a1: A1, a2: A2, a3: A3) => R>(name: string, fn: T): T;
<A1, A2, A3, A4, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4) => R>(name: string, fn: T): T;
<A1, A2, A3, A4, A5, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R>(name: string, fn: T): T;
<A1, A2, A3, A4, A5, A6, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a6: A6) => R>(name: string, fn: T): T;
<A1, R, T extends (a1: A1) => R>(name: string, fn: T): T & IAction;
<A1, A2, R, T extends (a1: A1, a2: A2) => R>(name: string, fn: T): T & IAction;
<A1, A2, A3, R, T extends (a1: A1, a2: A2, a3: A3) => R>(name: string, fn: T): T & IAction;
<A1, A2, A3, A4, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4) => R>(name: string, fn: T): T & IAction;
<A1, A2, A3, A4, A5, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R>(name: string, fn: T): T & IAction;
<A1, A2, A3, A4, A5, A6, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a6: A6) => R>(name: string, fn: T): T & IAction;

// generic forms
<T extends Function>(fn: T): T;
<T extends Function>(name: string, fn: T): T;
<T extends Function>(fn: T): T & IAction;
<T extends Function>(name: string, fn: T): T & IAction;

// named decorator
(customName: string): (target: Object, key: string, baseDescriptor?: PropertyDescriptor) => void;
Expand All @@ -32,12 +31,12 @@ export interface IActionFactory {
(target: Object, propertyKey: string, descriptor?: PropertyDescriptor): void;

// .bound
bound<A1, R, T extends (a1: A1) => R>(fn: T): T;
bound<A1, A2, R, T extends (a1: A1, a2: A2) => R>(fn: T): T;
bound<A1, A2, A3, R, T extends (a1: A1, a2: A2, a3: A3) => R>(fn: T): T;
bound<A1, A2, A3, A4, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4) => R>(fn: T): T;
bound<A1, A2, A3, A4, A5, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R>(fn: T): T;
bound<A1, A2, A3, A4, A5, A6, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a6: A6) => R>(fn: T): T;
bound<A1, R, T extends (a1: A1) => R>(fn: T): T & IAction;
bound<A1, A2, R, T extends (a1: A1, a2: A2) => R>(fn: T): T & IAction;
bound<A1, A2, A3, R, T extends (a1: A1, a2: A2, a3: A3) => R>(fn: T): T & IAction;
bound<A1, A2, A3, A4, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4) => R>(fn: T): T & IAction;
bound<A1, A2, A3, A4, A5, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => R>(fn: T): T & IAction;
bound<A1, A2, A3, A4, A5, A6, R, T extends (a1: A1, a2: A2, a3: A3, a4: A4, a6: A6) => R>(fn: T): T & IAction;

// .bound decorator
bound(target: Object, propertyKey: string, descriptor?: PropertyDescriptor): void;
Expand Down
8 changes: 6 additions & 2 deletions src/core/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import {isComputedValue} from "../core/computedvalue";
import {globalState} from "../core/globalstate";
import {getMessage} from "../utils/messages";

export interface IAction{
originalFn: Function
isMobxAction: boolean
}

export function createAction(actionName: string, fn: Function): Function {
export function createAction(actionName: string, fn: Function): Function & IAction {
invariant(typeof fn === "function", getMessage("m026"));
invariant(typeof actionName === "string" && actionName.length > 0, `actions should have valid names, got: '${actionName}'`);
const res = function () {
return executeAction(actionName, fn, this, arguments);
};
(res as any).originalFn = fn;
(res as any).isMobxAction = true;
return res;
return res as any;
}

export function executeAction(actionName: string, fn: Function, scope?: any, args?: IArguments) {
Expand Down
2 changes: 1 addition & 1 deletion src/mobx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export { IAtom, Atom, BaseAtom } from "./core/ato
export { IObservable, IDepTreeNode } from "./core/observable";
export { Reaction, IReactionPublic, IReactionDisposer } from "./core/reaction";
export { IDerivation, untracked, IDerivationState } from "./core/derivation";
export { useStrict, isStrictModeEnabled } from "./core/action";
export { useStrict, isStrictModeEnabled, IAction } from "./core/action";
export { spy } from "./core/spy";
export { IComputedValue } from "./core/computedvalue";

Expand Down

0 comments on commit 6bb7674

Please sign in to comment.