Comparing version 6.4.0 to 6.5.0
CHANGELOG | ||
=== | ||
6.5.0 | ||
-- | ||
Set | ||
- | ||
Error for throw cases instead of simple message for better call stack in those cases. | ||
6.4.0 | ||
@@ -4,0 +12,0 @@ -- |
13
index.js
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bootstrap = void 0; | ||
var s = require("./src/store"); | ||
var af = require("./src/actionFactory"); | ||
var d = require("./src/debug"); | ||
__export(require("./src/store")); | ||
__export(require("./src/actionFactory")); | ||
__export(require("./src/helpers")); | ||
exports.bootstrap = function (defaultState, onStateChanged, params) { | ||
__exportStar(require("./src/store"), exports); | ||
__exportStar(require("./src/actionFactory"), exports); | ||
__exportStar(require("./src/helpers"), exports); | ||
var bootstrap = function (defaultState, onStateChanged, params) { | ||
params.debugCallback && d.bootstrap(function (m, p) { return params.debugCallback && params.debugCallback("fun-model -> " + m, p); }); | ||
@@ -17,2 +15,3 @@ s.bootstrap(defaultState, params.withStateFreezing, params.subStateSeparator); | ||
}; | ||
exports.bootstrap = bootstrap; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "fun-model", | ||
"version": "6.4.0", | ||
"version": "6.5.0", | ||
"description": "fun-model is pure functional implementation of FLUX architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -95,3 +95,3 @@ "use strict"; | ||
testAction(); | ||
}).toThrow('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}).toThrowError('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -195,3 +195,3 @@ }); | ||
testAction(); | ||
}).toThrow('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}).toThrowError('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -198,0 +198,0 @@ }); |
@@ -117,3 +117,3 @@ import * as s from '../src/store'; | ||
testAction(); | ||
}).toThrow('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}).toThrowError('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -247,3 +247,3 @@ }); | ||
testAction(); | ||
}).toThrow('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}).toThrowError('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -250,0 +250,0 @@ }); |
@@ -88,3 +88,3 @@ "use strict"; | ||
var debug = jasmine.createSpy('debug'); | ||
debug_1.bootstrap(debug); | ||
(0, debug_1.bootstrap)(debug); | ||
h.shallowCopy('test'); | ||
@@ -91,0 +91,0 @@ expect(debug).toHaveBeenCalled(); |
@@ -54,3 +54,3 @@ "use strict"; | ||
expect(function () { return s.getState(s.rootCursor); }) | ||
.toThrow('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
.toThrowError('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -74,3 +74,3 @@ }); | ||
expect(function () { return s.getState({ key: 'notExistingKey' }); }) | ||
.toThrow('State for cursor key (notExistingKey) does not exist.'); | ||
.toThrowError('State for cursor key (notExistingKey) does not exist.'); | ||
}); | ||
@@ -112,3 +112,3 @@ it('returns udefined if cursor allows that', function () { | ||
expect(function () { return s.setState(s.rootCursor, {}); }) | ||
.toThrow('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
.toThrowError('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -126,3 +126,3 @@ }); | ||
expect(function () { return s.setState(cursor, {}); }) | ||
.toThrow(); | ||
.toThrowError(); | ||
}); | ||
@@ -129,0 +129,0 @@ it('creates empty object if cursor has not existing key if told to', function () { |
@@ -68,3 +68,3 @@ import * as s from '../src/store'; | ||
expect(() => s.getState<s.IState>(s.rootCursor)) | ||
.toThrow('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
.toThrowError('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -96,3 +96,3 @@ }); | ||
expect(() => s.getState<s.IState>({ key: 'notExistingKey' })) | ||
.toThrow('State for cursor key (notExistingKey) does not exist.'); | ||
.toThrowError('State for cursor key (notExistingKey) does not exist.'); | ||
}); | ||
@@ -146,3 +146,3 @@ | ||
expect(() => s.setState(s.rootCursor, {})) | ||
.toThrow('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
.toThrowError('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
}); | ||
@@ -163,3 +163,3 @@ }); | ||
expect(() => s.setState(cursor, {})) | ||
.toThrow(); | ||
.toThrowError(); | ||
}); | ||
@@ -166,0 +166,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nullableNumberCursor = exports.todosCursor = void 0; | ||
exports.default = (function () { | ||
@@ -4,0 +5,0 @@ return { |
@@ -11,5 +11,5 @@ import * as s from './store'; | ||
export declare type IParamLessActionHandler<TState> = (state: TState) => TState; | ||
export declare const createAction: <TState, TParams>(cursor: s.ICursor<TState> | (() => s.ICursor<TState>) | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>) => IAction<TParams>; | ||
export declare const createReplaceAction: <TState>(cursor: s.ICursor<TState> | (() => s.ICursor<TState>) | s.ICursorFactory<TState, TState>) => IAction<TState>; | ||
export declare const createParamLessAction: <TState>(cursor: s.ICursor<TState> | (() => s.ICursor<TState>) | s.ICursorFactory<TState, TState>, handler: IParamLessActionHandler<TState>) => IParamLessAction; | ||
export declare const createAction: <TState, TParams>(cursor: s.CursorType<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>) => IAction<TParams>; | ||
export declare const createReplaceAction: <TState>(cursor: s.CursorType<TState> | s.ICursorFactory<TState, TState>) => IAction<TState>; | ||
export declare const createParamLessAction: <TState>(cursor: s.CursorType<TState> | s.ICursorFactory<TState, TState>, handler: IParamLessActionHandler<TState>) => IParamLessAction; | ||
export interface IPair<TState, TParam> { | ||
@@ -16,0 +16,0 @@ cursor: s.ICursor<TState>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createParamLessActions = exports.createActions = exports.createParamLessAction = exports.createReplaceAction = exports.createAction = exports.bootstrap = void 0; | ||
var s = require("./store"); | ||
@@ -8,3 +9,3 @@ var d = require("./debug"); | ||
var exceptionHandling; | ||
exports.bootstrap = function (onStateChanged, withExceptionHandling) { | ||
var bootstrap = function (onStateChanged, withExceptionHandling) { | ||
if (withExceptionHandling === void 0) { withExceptionHandling = false; } | ||
@@ -16,7 +17,8 @@ stateChanged = onStateChanged; | ||
}; | ||
exports.bootstrap = bootstrap; | ||
var renderCallbackMustBeSetBefore = 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
exports.createAction = function (cursor, handler) { | ||
var createAction = function (cursor, handler) { | ||
return function (params) { | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
if (changeStateWithQueue(unifyCursor(cursor, params), function (state) { return handler(state, params); })) { | ||
@@ -28,9 +30,11 @@ stateChanged(); | ||
}; | ||
exports.createReplaceAction = function (cursor) { | ||
return exports.createAction(cursor, function (_state, params) { return params; }); | ||
exports.createAction = createAction; | ||
var createReplaceAction = function (cursor) { | ||
return (0, exports.createAction)(cursor, function (_state, params) { return params; }); | ||
}; | ||
exports.createParamLessAction = function (cursor, handler) { | ||
exports.createReplaceAction = createReplaceAction; | ||
var createParamLessAction = function (cursor, handler) { | ||
return function () { | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
if (changeStateWithQueue(unifyCursor(cursor, null), handler)) { | ||
@@ -42,2 +46,3 @@ stateChanged(); | ||
}; | ||
exports.createParamLessAction = createParamLessAction; | ||
function unifyCursor(cursor, params) { | ||
@@ -48,3 +53,3 @@ return cursor.create instanceof Function | ||
} | ||
exports.createActions = function () { | ||
var createActions = function () { | ||
var pairs = []; | ||
@@ -56,3 +61,3 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
var changed = false; | ||
@@ -72,3 +77,4 @@ var _loop_1 = function () { | ||
}; | ||
exports.createParamLessActions = function () { | ||
exports.createActions = createActions; | ||
var createParamLessActions = function () { | ||
var pairs = []; | ||
@@ -80,3 +86,3 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
var changed = false; | ||
@@ -92,2 +98,3 @@ for (var i in pairs) | ||
}; | ||
exports.createParamLessActions = createParamLessActions; | ||
var queueOfHandlers = []; | ||
@@ -94,0 +101,0 @@ function changeStateWithQueue(cursor, handler) { |
@@ -35,4 +35,4 @@ import * as s from './store'; | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
if (changeStateWithQueue(unifyCursor(cursor, params), (state) => handler(state, params))) { | ||
@@ -54,3 +54,3 @@ stateChanged(); | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
@@ -78,3 +78,3 @@ if (changeStateWithQueue(unifyCursor(cursor, null), handler)) { | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
@@ -100,3 +100,3 @@ let changed = false; | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
throw new Error(renderCallbackMustBeSetBefore); | ||
let changed = false; | ||
@@ -103,0 +103,0 @@ for (var i in pairs) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.log = exports.bootstrap = exports.debug = void 0; | ||
exports.debug = undefined; | ||
exports.bootstrap = function (debugCallback) { | ||
var bootstrap = function (debugCallback) { | ||
exports.debug = debugCallback; | ||
}; | ||
exports.log = function (message, params) { | ||
exports.debug && exports.debug(message, params); | ||
exports.bootstrap = bootstrap; | ||
var log = function (message, params) { | ||
exports.debug && (0, exports.debug)(message, params); | ||
}; | ||
exports.log = log; | ||
//# sourceMappingURL=debug.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isFunction = exports.deepFreeze = exports.objectShallowCopy = exports.shallowCopy = void 0; | ||
var debug_1 = require("./debug"); | ||
function shallowCopy(source, callback) { | ||
if (source instanceof Array) { | ||
source = source.slice(); | ||
source = __spreadArray([], source, true); | ||
var result_1 = callback ? callback(source) : undefined; | ||
@@ -14,3 +15,3 @@ return result_1 || source; | ||
if (debug_1.debug) { | ||
debug_1.debug("Shallow copy should not be used for primitive types."); | ||
(0, debug_1.debug)("Shallow copy should not be used for primitive types."); | ||
} | ||
@@ -17,0 +18,0 @@ var result = callback && callback(source); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setState = exports.getState = exports.isExistingCursor = exports.bootstrap = exports.rootCursor = exports.isCursorFunction = exports.createNestedCursorFactory = exports.createNestedCursor = void 0; | ||
var h = require("./helpers"); | ||
@@ -27,3 +28,3 @@ var d = require("./debug"); | ||
}; | ||
exports.bootstrap = function (defaultState, withStateFreezing, subStateSeparator) { | ||
var bootstrap = function (defaultState, withStateFreezing, subStateSeparator) { | ||
if (withStateFreezing === void 0) { withStateFreezing = false; } | ||
@@ -35,3 +36,4 @@ if (subStateSeparator === void 0) { subStateSeparator = '.'; } | ||
}; | ||
exports.isExistingCursor = function (cursor) { | ||
exports.bootstrap = bootstrap; | ||
var isExistingCursor = function (cursor) { | ||
cursor = isCursorFunction(cursor) ? cursor() : cursor; | ||
@@ -58,3 +60,3 @@ var hasExistingInnerStateInArray = function (innerState, path) { | ||
if (!isSetDefaultState(state) || !isValidCursorKey(cursor)) | ||
throw 'Invalid operation.'; | ||
throw new Error('Invalid operation.'); | ||
return cursor.key === rootStateKey | ||
@@ -64,3 +66,4 @@ ? true | ||
}; | ||
exports.getState = function (cursor) { | ||
exports.isExistingCursor = isExistingCursor; | ||
var getState = function (cursor) { | ||
var cursorValue = isCursorFunction(cursor) ? cursor() : cursor; | ||
@@ -80,3 +83,3 @@ var getInnerState = function (innerState, path) { | ||
if (!isSetDefaultState(state) || !isValidCursorKey(cursorValue)) | ||
throw 'Invalid operation.'; | ||
throw new Error('Invalid operation.'); | ||
return (cursorValue.key === rootStateKey | ||
@@ -86,3 +89,4 @@ ? state | ||
}; | ||
exports.setState = function (cursor, updatedState, canCreateObjectsOnPath) { | ||
exports.getState = getState; | ||
var setState = function (cursor, updatedState, canCreateObjectsOnPath) { | ||
if (canCreateObjectsOnPath === void 0) { canCreateObjectsOnPath = false; } | ||
@@ -104,3 +108,3 @@ var cursorValue = isCursorFunction(cursor) ? cursor() : cursor; | ||
var index = Number(path.shift()); | ||
newSubState = prop.slice(); | ||
newSubState = __spreadArray([], prop, true); | ||
newSubState[index] = setInnerState(newSubState[index], path); | ||
@@ -117,3 +121,3 @@ } | ||
if (!isSetDefaultState(state) || !isValidCursorKey(cursorValue)) | ||
throw 'Invalid operation.'; | ||
throw new Error('Invalid operation.'); | ||
state = | ||
@@ -127,2 +131,3 @@ cursorValue.key === rootStateKey | ||
}; | ||
exports.setState = setState; | ||
function checkSubstate(s, subPath, remainingPath, cursor) { | ||
@@ -132,3 +137,3 @@ if (remainingPath.length === 0 && cursor.isUndefinable) | ||
if (s[subPath] === undefined) | ||
throw "State for cursor key (" + cursor.key + ") does not exist."; | ||
throw new Error("State for cursor key (" + cursor.key + ") does not exist."); | ||
} | ||
@@ -141,3 +146,3 @@ function createSubstate(s, subPath) { | ||
if (state === null) | ||
throw 'Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
throw new Error('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
return true; | ||
@@ -147,5 +152,5 @@ } | ||
if (cursor.key === null) | ||
throw 'Cursor key cannot be null.'; | ||
throw new Error('Cursor key cannot be null.'); | ||
return true; | ||
} | ||
//# sourceMappingURL=store.js.map |
@@ -71,3 +71,3 @@ import * as h from './helpers'; | ||
if (!isSetDefaultState(state) || !isValidCursorKey(cursor)) | ||
throw 'Invalid operation.'; | ||
throw new Error('Invalid operation.'); | ||
@@ -95,3 +95,3 @@ return cursor.key === rootStateKey | ||
if (!isSetDefaultState(state) || !isValidCursorKey(cursorValue)) | ||
throw 'Invalid operation.'; | ||
throw new Error('Invalid operation.'); | ||
@@ -135,3 +135,3 @@ return <TState>(cursorValue.key === rootStateKey | ||
if (!isSetDefaultState(state) || !isValidCursorKey(cursorValue)) | ||
throw 'Invalid operation.'; | ||
throw new Error('Invalid operation.'); | ||
@@ -151,3 +151,3 @@ state = | ||
if ((<any>s)[subPath] === undefined) | ||
throw `State for cursor key (${cursor.key}) does not exist.`; | ||
throw new Error(`State for cursor key (${cursor.key}) does not exist.`); | ||
} | ||
@@ -162,3 +162,3 @@ | ||
if (state === null) | ||
throw 'Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
throw new Error('Default state must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'); | ||
return true; | ||
@@ -169,4 +169,4 @@ } | ||
if (cursor.key === null) | ||
throw 'Cursor key cannot be null.'; | ||
throw new Error( 'Cursor key cannot be null.'); | ||
return true; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
289188
2057
44