Comparing version 4.0.1 to 4.1.0
CHANGELOG | ||
=== | ||
4.1.0 | ||
-- | ||
New Features | ||
- | ||
Added withExceptionHandling optional bootstrap parameter. It should be useful in dev. mode. | ||
4.0.0 | ||
@@ -4,0 +12,0 @@ -- |
@@ -14,3 +14,3 @@ "use strict"; | ||
s.bootstrap(defaultState, params.withStateFreezing, params.subStateSeparator); | ||
af.bootstrap(onStateChanged); | ||
af.bootstrap(onStateChanged, params.withExceptionHandling); | ||
}; |
@@ -13,2 +13,3 @@ import * as s from './src/store'; | ||
withStateFreezing?: boolean | (() => boolean); | ||
withExceptionHandling?: boolean | (() => boolean); | ||
subStateSeparator?: string; | ||
@@ -20,3 +21,3 @@ } | ||
s.bootstrap(defaultState, params.withStateFreezing, params.subStateSeparator); | ||
af.bootstrap(onStateChanged); | ||
af.bootstrap(onStateChanged, params.withExceptionHandling); | ||
}; |
{ | ||
"name": "fun-model", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "fun-model is pure functional implementation of FLUX architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -55,2 +55,34 @@ "use strict"; | ||
describe('createAction', function () { | ||
describe('when action threw during handling and catching have not been enabled', function () { | ||
var renderCallback; | ||
var throwingAction; | ||
beforeEach(function () { | ||
renderCallback = jasmine.createSpy('render'); | ||
af.bootstrap(renderCallback, false); | ||
throwingAction = af.createAction(NestedCursorTestFixture, function () { | ||
throw 'MyDummyException'; | ||
}); | ||
}); | ||
it('throws', function () { | ||
expect(throwingAction).toThrow(); | ||
}); | ||
}); | ||
describe('when action threw during handling and catching have been enabled', function () { | ||
var renderCallback; | ||
var throwingAction; | ||
beforeEach(function () { | ||
renderCallback = jasmine.createSpy('render'); | ||
af.bootstrap(renderCallback, true); | ||
throwingAction = af.createAction(NestedCursorTestFixture, function () { | ||
throw 'MyDummyException'; | ||
}); | ||
}); | ||
it('does not throw', function () { | ||
expect(throwingAction).not.toThrow(); | ||
}); | ||
it('logs error', function () { | ||
throwingAction(); | ||
expect(debugCallback).toHaveBeenCalledWith('Action factory has been initialized.', undefined); | ||
}); | ||
}); | ||
describe('when renderCallback has not been set', function () { | ||
@@ -57,0 +89,0 @@ it('does not throw if action has been only declared.', function () { |
@@ -72,2 +72,40 @@ import * as s from '../src/store'; | ||
describe('createAction', () => { | ||
describe('when action threw during handling and catching have not been enabled', () => { | ||
let renderCallback: () => void; | ||
let throwingAction: af.IAction<{}>; | ||
beforeEach(() => { | ||
renderCallback = jasmine.createSpy('render'); | ||
af.bootstrap(renderCallback, false); | ||
throwingAction = af.createAction(NestedCursorTestFixture, () => { | ||
throw 'MyDummyException'; | ||
}); | ||
}); | ||
it('throws', () => { | ||
expect(throwingAction).toThrow(); | ||
}); | ||
}); | ||
describe('when action threw during handling and catching have been enabled', () => { | ||
let renderCallback: () => void; | ||
let throwingAction: af.IAction<{}>; | ||
beforeEach(() => { | ||
renderCallback = jasmine.createSpy('render'); | ||
af.bootstrap(renderCallback, true); | ||
throwingAction = af.createAction(NestedCursorTestFixture, () => { | ||
throw 'MyDummyException'; | ||
}); | ||
}); | ||
it('does not throw', () => { | ||
expect(throwingAction).not.toThrow(); | ||
}); | ||
it('logs error', () => { | ||
throwingAction(); | ||
expect(debugCallback).toHaveBeenCalledWith('Action factory has been initialized.', undefined); | ||
}); | ||
}); | ||
describe('when renderCallback has not been set', () => { | ||
@@ -220,3 +258,3 @@ it('does not throw if action has been only declared.', () => { | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -223,0 +261,0 @@ |
"use strict"; | ||
var s = require('./store'); | ||
var d = require('./debug'); | ||
var render = null; | ||
exports.bootstrap = function (renderCallback) { | ||
render = renderCallback; | ||
var h = require('./helpers'); | ||
var stateChanged = null; | ||
var exceptionHandling; | ||
exports.bootstrap = function (onStateChanged, withExceptionHandling) { | ||
if (withExceptionHandling === void 0) { withExceptionHandling = false; } | ||
stateChanged = onStateChanged; | ||
queueOfHandlers = []; | ||
exceptionHandling = withExceptionHandling; | ||
d.log('Action factory has been initialized.'); | ||
@@ -12,6 +16,6 @@ }; | ||
return (function (params) { | ||
if (render === null) | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
if (changeStateWithQueue(unifyCursor(cursor, params), handler, params)) { | ||
render(); | ||
stateChanged(); | ||
d.log('Rendering invoked...'); | ||
@@ -30,3 +34,3 @@ } | ||
return (function (params) { | ||
if (render === null) | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
@@ -40,3 +44,3 @@ var changed = false; | ||
} | ||
changed && render(); | ||
changed && stateChanged(); | ||
}); | ||
@@ -52,3 +56,11 @@ }; | ||
var n = queueOfHandlers[0]; | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
if (h.isFunction(exceptionHandling) ? exceptionHandling() : exceptionHandling) | ||
try { | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
} | ||
catch (error) { | ||
d.log('Error in action handling: ', error); | ||
} | ||
else | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
queueOfHandlers.shift(); | ||
@@ -55,0 +67,0 @@ } |
import * as s from './store'; | ||
import * as d from './debug'; | ||
import * as h from './helpers'; | ||
let render: (() => void) | null = null; | ||
let stateChanged: (() => void) | null = null; | ||
let exceptionHandling: boolean | (() => boolean); | ||
export let bootstrap = (renderCallback: (() => void) | null) => { | ||
render = renderCallback; | ||
export const bootstrap = (onStateChanged: (() => void) | null, withExceptionHandling: boolean | (() => boolean) = false) => { | ||
stateChanged = onStateChanged; | ||
queueOfHandlers = []; | ||
exceptionHandling = withExceptionHandling; | ||
d.log('Action factory has been initialized.'); | ||
@@ -21,7 +24,7 @@ }; | ||
return <IAction<TParams>>((params?: TParams): void => { | ||
if (render === null) | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
if (changeStateWithQueue(unifyCursor<TState, TParams>(cursor, params), handler, params)) { | ||
render(); | ||
stateChanged(); | ||
d.log('Rendering invoked...'); | ||
@@ -43,3 +46,3 @@ } | ||
return <IAction<TParams>>((params?: TParams) => { | ||
if (render === null) | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
@@ -53,3 +56,3 @@ let changed = false; | ||
} | ||
changed && render(); | ||
changed && stateChanged(); | ||
}); | ||
@@ -73,3 +76,11 @@ } | ||
let n = queueOfHandlers[0]; | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
if (h.isFunction(exceptionHandling) ? exceptionHandling() : exceptionHandling) | ||
try { | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
} catch (error) { | ||
d.log('Error in action handling: ', error); | ||
} | ||
else | ||
isStateChanged = changeState(n.cursor, n.handler, n.params) || isStateChanged; | ||
queueOfHandlers.shift(); | ||
@@ -76,0 +87,0 @@ } |
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
227377
1529