Comparing version 2.0.0 to 2.1.0
"use strict"; | ||
var internalDispatchWithMiddleware = finalDispatch; | ||
var globalContext_1 = require('./globalContext'); | ||
function applyMiddleware() { | ||
@@ -12,3 +12,3 @@ var middleware = []; | ||
} | ||
internalDispatchWithMiddleware = next; | ||
globalContext_1.getGlobalContext().dispatchWithMiddleware = next; | ||
} | ||
@@ -21,3 +21,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function dispatchWithMiddleware(action, actionType, args, actionContext) { | ||
internalDispatchWithMiddleware(action, actionType, args, actionContext); | ||
if (!globalContext_1.getGlobalContext().dispatchWithMiddleware) { | ||
globalContext_1.getGlobalContext().dispatchWithMiddleware = finalDispatch; | ||
} | ||
globalContext_1.getGlobalContext().dispatchWithMiddleware(action, actionType, args, actionContext); | ||
} | ||
@@ -24,0 +27,0 @@ exports.dispatchWithMiddleware = dispatchWithMiddleware; |
"use strict"; | ||
var mobx_1 = require('mobx'); | ||
var applyMiddleware_1 = require('./applyMiddleware'); | ||
var inDispatch = 0; | ||
var globalContext_1 = require('./globalContext'); | ||
function dispatch(action, actionType, args, actionContext) { | ||
inDispatch++; | ||
globalContext_1.getGlobalContext().inDispatch++; | ||
mobx_1.action(actionType ? actionType : "(anonymous action)", function () { | ||
applyMiddleware_1.dispatchWithMiddleware(action, actionType, args, actionContext); | ||
})(); | ||
inDispatch--; | ||
globalContext_1.getGlobalContext().inDispatch--; | ||
} | ||
@@ -17,5 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
mobx_1.spy(function (change) { | ||
if (!inDispatch && change.type == "action") { | ||
if (!globalContext_1.getGlobalContext().inDispatch && change.type == "action") { | ||
throw new Error('The state may only be changed by a SatchelJS action.'); | ||
} | ||
}); |
@@ -12,3 +12,1 @@ "use strict"; | ||
exports.action = action_1.default; | ||
var initialize_1 = require('./initialize'); | ||
initialize_1.default(); |
import { ObservableMap } from 'mobx'; | ||
declare var rootStore: ObservableMap<any>; | ||
export default rootStore; | ||
declare var _default: ObservableMap<any>; | ||
export default _default; |
"use strict"; | ||
var mobx_1 = require('mobx'); | ||
var rootStore = mobx_1.map({}); | ||
var globalContext_1 = require('./globalContext'); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = rootStore; | ||
exports.default = globalContext_1.getGlobalContext().rootStore; |
{ | ||
"name": "satcheljs", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Store implementation for functional reactive flux.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/src/index.js", |
@@ -5,4 +5,4 @@ import ActionContext from './ActionContext'; | ||
import Middleware from './Middleware'; | ||
import { getGlobalContext } from './globalContext'; | ||
let internalDispatchWithMiddleware = finalDispatch; | ||
@@ -15,3 +15,3 @@ export default function applyMiddleware(...middleware: Middleware[]) { | ||
internalDispatchWithMiddleware = next; | ||
getGlobalContext().dispatchWithMiddleware = next; | ||
} | ||
@@ -24,3 +24,7 @@ | ||
export function dispatchWithMiddleware(action: ActionFunction, actionType: string, args: IArguments, actionContext: ActionContext) { | ||
internalDispatchWithMiddleware(action, actionType, args, actionContext); | ||
if (!getGlobalContext().dispatchWithMiddleware) { | ||
getGlobalContext().dispatchWithMiddleware = finalDispatch; | ||
} | ||
getGlobalContext().dispatchWithMiddleware(action, actionType, args, actionContext); | ||
} | ||
@@ -27,0 +31,0 @@ |
@@ -6,7 +6,6 @@ import {useStrict, spy, action as mobxAction} from 'mobx'; | ||
import { dispatchWithMiddleware } from './applyMiddleware'; | ||
import { getGlobalContext } from './globalContext'; | ||
var inDispatch: number = 0; | ||
export default function dispatch(action: ActionFunction, actionType: string, args: IArguments, actionContext: ActionContext): void { | ||
inDispatch++; | ||
getGlobalContext().inDispatch++; | ||
@@ -19,3 +18,3 @@ mobxAction( | ||
inDispatch--; | ||
getGlobalContext().inDispatch--; | ||
} | ||
@@ -27,5 +26,5 @@ | ||
spy((change) => { | ||
if (!inDispatch && change.type == "action") { | ||
if (!getGlobalContext().inDispatch && change.type == "action") { | ||
throw new Error('The state may only be changed by a SatchelJS action.'); | ||
} | ||
}); |
@@ -9,6 +9,2 @@ export { default as rootStore } from './rootStore'; | ||
export { default as createStore } from './createStore'; | ||
export { default as action } from './action'; | ||
import initialize from './initialize'; | ||
initialize(); | ||
export { default as action } from './action'; |
@@ -1,4 +0,4 @@ | ||
import { map, ObservableMap } from 'mobx'; | ||
import { ObservableMap } from 'mobx'; | ||
import { getGlobalContext } from './globalContext'; | ||
var rootStore: ObservableMap<any> = map({}); | ||
export default rootStore; | ||
export default getGlobalContext().rootStore; |
@@ -9,3 +9,2 @@ import 'jasmine'; | ||
var backupConsoleError = console.error; | ||
@@ -74,3 +73,3 @@ | ||
expect(count).toBe(2); | ||
}); | ||
}); | ||
}); |
61590
1268