Comparing version 6.0.0 to 6.1.0
{ | ||
"name": "fun-model", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "fun-model is pure functional implementation of FLUX architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -160,3 +160,3 @@ "use strict"; | ||
}); | ||
it('replaces if the state has not been same', function () { | ||
it('calls render callback if the state has not been same', function () { | ||
givenStore(aState('nestedStateValue')); | ||
@@ -167,3 +167,3 @@ var testAction = af.createReplaceAction(NestedStateCursorTestFixture); | ||
}); | ||
it('does not replace the same state', function () { | ||
it('does not call render callback for the same state', function () { | ||
givenStore(aState('nestedStateValue')); | ||
@@ -174,2 +174,14 @@ var testAction = af.createReplaceAction(NestedStateCursorTestFixture); | ||
}); | ||
it('replaces if the state has not been same', function () { | ||
givenStore(aState('nestedStateValue')); | ||
var testAction = af.createReplaceAction(NestedStateCursorTestFixture); | ||
testAction('newNestedStateValue'); | ||
expect(s.getState(NestedStateCursorTestFixture)).toBe('newNestedStateValue'); | ||
}); | ||
it('does not replace the same state', function () { | ||
givenStore(aState('nestedStateValue')); | ||
var testAction = af.createReplaceAction(NestedStateCursorTestFixture); | ||
testAction('nestedStateValue'); | ||
expect(s.getState(NestedStateCursorTestFixture)).toBe('nestedStateValue'); | ||
}); | ||
}); | ||
@@ -176,0 +188,0 @@ describe('createActions', function () { |
@@ -204,3 +204,3 @@ import * as s from '../src/store'; | ||
}); | ||
it('replaces if the state has not been same', () => { | ||
it('calls render callback if the state has not been same', () => { | ||
givenStore(aState('nestedStateValue')); | ||
@@ -210,5 +210,6 @@ const testAction = af.createReplaceAction<string>(NestedStateCursorTestFixture); | ||
testAction('newNestedStateValue'); | ||
expect(renderCallback).toHaveBeenCalled(); | ||
}); | ||
it('does not replace the same state', () => { | ||
it('does not call render callback for the same state', () => { | ||
givenStore(aState('nestedStateValue')); | ||
@@ -220,2 +221,18 @@ const testAction = af.createReplaceAction<string>(NestedStateCursorTestFixture); | ||
}); | ||
it('replaces if the state has not been same', () => { | ||
givenStore(aState('nestedStateValue')); | ||
const testAction = af.createReplaceAction<string>(NestedStateCursorTestFixture); | ||
testAction('newNestedStateValue'); | ||
expect(s.getState(NestedStateCursorTestFixture)).toBe('newNestedStateValue'); | ||
}); | ||
it('does not replace the same state', () => { | ||
givenStore(aState('nestedStateValue')); | ||
const testAction = af.createReplaceAction<string>(NestedStateCursorTestFixture); | ||
testAction('nestedStateValue'); | ||
expect(s.getState(NestedStateCursorTestFixture)).toBe('nestedStateValue'); | ||
}); | ||
}) | ||
@@ -222,0 +239,0 @@ |
@@ -9,16 +9,16 @@ import * as s from './store'; | ||
} | ||
export declare type IActionHandler<TState extends s.IState | null, TParams> = (state: TState, t: TParams) => TState; | ||
export declare type IParamLessActionHandler<TState extends s.IState | null> = (state: TState) => TState; | ||
export declare const createAction: <TState extends s.IState | null, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>) => IAction<TParams>; | ||
export declare const createReplaceAction: <TState extends s.IState | null>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TState>) => IAction<TState>; | ||
export declare const createParamLessAction: <TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: IParamLessActionHandler<TState>) => IParamLessAction; | ||
export interface IPair<TState extends s.IState | null, TParam> { | ||
export declare type IActionHandler<TState, TParams> = (state: TState, t: TParams) => TState; | ||
export declare type IParamLessActionHandler<TState> = (state: TState) => TState; | ||
export declare const createAction: <TState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>) => IAction<TParams>; | ||
export declare const createReplaceAction: <TState>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TState>) => IAction<TState>; | ||
export declare const createParamLessAction: <TState>(cursor: s.ICursor<TState>, handler: IParamLessActionHandler<TState>) => IParamLessAction; | ||
export interface IPair<TState, TParam> { | ||
cursor: s.ICursor<TState>; | ||
handler: (state: TState, t: TParam) => TState; | ||
} | ||
export declare const createActions: <TState extends s.IState | null, TParams>(...pairs: IPair<TState, TParams>[]) => IAction<TParams>; | ||
export interface IParamLessPair<TState extends s.IState> { | ||
export declare const createActions: <TState, TParams>(...pairs: IPair<TState, TParams>[]) => IAction<TParams>; | ||
export interface IParamLessPair<TState> { | ||
cursor: s.ICursor<TState>; | ||
handler: (state: TState) => TState; | ||
} | ||
export declare const createParamLessActions: <TState extends s.IState>(...pairs: IParamLessPair<TState>[]) => IParamLessAction; | ||
export declare const createParamLessActions: <TState>(...pairs: IParamLessPair<TState>[]) => IParamLessAction; |
@@ -15,6 +15,7 @@ "use strict"; | ||
}; | ||
var renderCallbackMustBeSetBefore = 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
exports.createAction = function (cursor, handler) { | ||
return (function (params) { | ||
return function (params) { | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
throw renderCallbackMustBeSetBefore; | ||
if (changeStateWithQueue(unifyCursor(cursor, params), function (state) { return handler(state, params); })) { | ||
@@ -24,18 +25,11 @@ stateChanged(); | ||
} | ||
}); | ||
}; | ||
}; | ||
exports.createReplaceAction = function (cursor) { | ||
return (function (params) { | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
if (changeStateWithQueue(unifyCursor(cursor, params), function (_state) { return params; })) { | ||
stateChanged(); | ||
d.log('Rendering invoked...'); | ||
} | ||
}); | ||
return exports.createAction(cursor, function (_state, params) { return params; }); | ||
}; | ||
exports.createParamLessAction = function (cursor, handler) { | ||
return (function () { | ||
return function () { | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
throw renderCallbackMustBeSetBefore; | ||
if (changeStateWithQueue(cursor, handler)) { | ||
@@ -45,3 +39,3 @@ stateChanged(); | ||
} | ||
}); | ||
}; | ||
}; | ||
@@ -56,5 +50,5 @@ function unifyCursor(cursor, params) { | ||
} | ||
return (function (params) { | ||
return function (params) { | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
throw renderCallbackMustBeSetBefore; | ||
var changed = false; | ||
@@ -72,3 +66,3 @@ var _loop_1 = function () { | ||
changed && stateChanged(); | ||
}); | ||
}; | ||
}; | ||
@@ -80,5 +74,5 @@ exports.createParamLessActions = function () { | ||
} | ||
return (function () { | ||
return function () { | ||
if (stateChanged === null) | ||
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
throw renderCallbackMustBeSetBefore; | ||
var changed = false; | ||
@@ -92,3 +86,3 @@ for (var i in pairs) | ||
changed && stateChanged(); | ||
}); | ||
}; | ||
}; | ||
@@ -95,0 +89,0 @@ var queueOfHandlers = []; |
@@ -23,13 +23,13 @@ import * as s from './store'; | ||
export type IActionHandler<TState extends s.IState | null, TParams> = (state: TState, t: TParams) => TState; | ||
export type IActionHandler<TState, TParams> = (state: TState, t: TParams) => TState; | ||
export type IParamLessActionHandler<TState extends s.IState | null> = (state: TState) => TState; | ||
export type IParamLessActionHandler<TState> = (state: TState) => TState; | ||
type IInternalActionHandler<TState extends s.IState | null> = (state: TState) => TState; | ||
type IInternalActionHandler<TState> = (state: TState) => TState; | ||
const renderCallbackMustBeSetBefore = 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).'; | ||
export const createAction = <TState extends s.IState | null, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>) | ||
export const createAction = <TState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>) | ||
: IAction<TParams> => { | ||
return <IAction<TParams>>((params: TParams): void => { | ||
return (params: TParams): void => { | ||
if (stateChanged === null) | ||
@@ -42,21 +42,13 @@ throw renderCallbackMustBeSetBefore; | ||
} | ||
}); | ||
}; | ||
}; | ||
export const createReplaceAction = <TState extends s.IState | null>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TState>) | ||
export const createReplaceAction = <TState>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TState>) | ||
: IAction<TState> => { | ||
return <IAction<TState>>((params: TState): void => { | ||
if (stateChanged === null) | ||
throw renderCallbackMustBeSetBefore; | ||
if (changeStateWithQueue(unifyCursor<TState, TState>(cursor, params), (_state) => params)) { | ||
stateChanged(); | ||
d.log('Rendering invoked...'); | ||
} | ||
}); | ||
return createAction(cursor, (_state, params) => params); | ||
}; | ||
export const createParamLessAction = <TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: IParamLessActionHandler<TState>) | ||
export const createParamLessAction = <TState>(cursor: s.ICursor<TState>, handler: IParamLessActionHandler<TState>) | ||
: IParamLessAction => { | ||
return <IParamLessAction>((): void => { | ||
return (): void => { | ||
if (stateChanged === null) | ||
@@ -69,10 +61,10 @@ throw renderCallbackMustBeSetBefore; | ||
} | ||
}); | ||
}; | ||
}; | ||
function unifyCursor<TState extends s.IState | null, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, params: TParams): s.ICursor<TState> { | ||
function unifyCursor<TState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, params: TParams): s.ICursor<TState> { | ||
return (<s.ICursorFactory<TState, TParams>>cursor).create instanceof Function ? (<s.ICursorFactory<TState, TParams>>cursor).create(params) : <s.ICursor<TState>>cursor; | ||
} | ||
export interface IPair<TState extends s.IState | null, TParam> { | ||
export interface IPair<TState, TParam> { | ||
cursor: s.ICursor<TState>; | ||
@@ -82,4 +74,4 @@ handler: (state: TState, t: TParam) => TState | ||
export const createActions = <TState extends s.IState | null, TParams>(...pairs: IPair<TState, TParams>[]) => { | ||
return <IAction<TParams>>((params: TParams) => { | ||
export const createActions = <TState, TParams>(...pairs: IPair<TState, TParams>[]): IAction<TParams> => { | ||
return (params: TParams) => { | ||
if (stateChanged === null) | ||
@@ -96,6 +88,6 @@ throw renderCallbackMustBeSetBefore; | ||
changed && stateChanged(); | ||
}); | ||
}; | ||
}; | ||
export interface IParamLessPair<TState extends s.IState> { | ||
export interface IParamLessPair<TState> { | ||
cursor: s.ICursor<TState>; | ||
@@ -105,4 +97,4 @@ handler: (state: TState) => TState | ||
export const createParamLessActions = <TState extends s.IState>(...pairs: IParamLessPair<TState>[]) => { | ||
return <IParamLessAction>(() => { | ||
export const createParamLessActions = <TState>(...pairs: IParamLessPair<TState>[]): IParamLessAction => { | ||
return () => { | ||
if (stateChanged === null) | ||
@@ -118,6 +110,6 @@ throw renderCallbackMustBeSetBefore; | ||
changed && stateChanged(); | ||
}); | ||
}; | ||
}; | ||
interface IQueuedHandling<TState extends s.IState | null> { | ||
interface IQueuedHandling<TState> { | ||
cursor: s.ICursor<TState>; | ||
@@ -127,4 +119,4 @@ handler: IInternalActionHandler<TState>; | ||
let queueOfHandlers: IQueuedHandling<s.IState | null>[] = []; | ||
function changeStateWithQueue<TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
let queueOfHandlers: IQueuedHandling<any>[] = []; | ||
function changeStateWithQueue<TState>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
: boolean { | ||
@@ -152,3 +144,3 @@ queueOfHandlers.push({ cursor, handler }); | ||
function changeState<TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
function changeState<TState>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
: boolean { | ||
@@ -155,0 +147,0 @@ let oldState = s.getState(cursor); |
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
245832
1939