Comparing version 5.0.0 to 5.0.1
{ | ||
"name": "fun-model", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "fun-model is pure functional implementation of FLUX architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -9,11 +9,11 @@ import * as s from './store'; | ||
} | ||
export declare type IActionHandler<TState extends s.IState, TParams> = (state: TState, t: TParams) => TState; | ||
export declare type IParamLessActionHandler<TState extends s.IState> = (state: TState) => TState; | ||
export declare const createAction: <TState extends s.IState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler?: (state: TState, t: TParams) => TState) => IAction<TParams>; | ||
export declare const createParamLessAction: <TState extends s.IState>(cursor: s.ICursor<TState>, handler: (state: TState) => TState) => IParamLessAction; | ||
export interface IPair<TState extends s.IState, TParam> { | ||
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?: (state: TState, t: TParams) => TState) => IAction<TParams>; | ||
export declare const createParamLessAction: <TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: (state: TState) => TState) => IParamLessAction; | ||
export interface IPair<TState extends s.IState | null, TParam> { | ||
cursor: s.ICursor<TState>; | ||
handler: (state: TState, t: TParam) => TState; | ||
} | ||
export declare const createActions: <TState extends s.IState, TParams>(...pairs: IPair<TState, TParams>[]) => IAction<TParams>; | ||
export declare const createActions: <TState extends s.IState | null, TParams>(...pairs: IPair<TState, TParams>[]) => IAction<TParams>; | ||
export interface IParamLessPair<TState extends s.IState> { | ||
@@ -20,0 +20,0 @@ cursor: s.ICursor<TState>; |
@@ -23,11 +23,11 @@ import * as s from './store'; | ||
export type IActionHandler<TState extends s.IState, TParams> = (state: TState, t: TParams) => TState; | ||
export type IActionHandler<TState extends s.IState | null, TParams> = (state: TState, t: TParams) => TState; | ||
export type IParamLessActionHandler<TState extends s.IState> = (state: TState) => TState; | ||
export type IParamLessActionHandler<TState extends s.IState | null> = (state: TState) => TState; | ||
type IInternalActionHandler<TState extends s.IState> = (state: TState) => TState; | ||
type IInternalActionHandler<TState extends s.IState | null> = (state: TState) => TState; | ||
function defaultHandler<TValue>(_oldValue: TValue, newValue: TValue) { return newValue; } | ||
export const createAction = <TState extends s.IState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams> = defaultHandler) | ||
export const createAction = <TState extends s.IState | null, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams> = defaultHandler) | ||
: IAction<TParams> => { | ||
@@ -45,3 +45,3 @@ return <IAction<TParams>>((params: TParams): void => { | ||
export const createParamLessAction = <TState extends s.IState>(cursor: s.ICursor<TState>, handler: IParamLessActionHandler<TState>) | ||
export const createParamLessAction = <TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: IParamLessActionHandler<TState>) | ||
: IParamLessAction => { | ||
@@ -59,7 +59,7 @@ return <IParamLessAction>((): void => { | ||
function unifyCursor<TState extends s.IState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, params: TParams): s.ICursor<TState> { | ||
function unifyCursor<TState extends s.IState | null, 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, TParam> { | ||
export interface IPair<TState extends s.IState | null, TParam> { | ||
cursor: s.ICursor<TState>; | ||
@@ -69,3 +69,3 @@ handler: (state: TState, t: TParam) => TState | ||
export const createActions = <TState extends s.IState, TParams>(...pairs: IPair<TState, TParams>[]) => { | ||
export const createActions = <TState extends s.IState | null, TParams>(...pairs: IPair<TState, TParams>[]) => { | ||
return <IAction<TParams>>((params: TParams) => { | ||
@@ -105,3 +105,3 @@ if (stateChanged === null) | ||
interface IQueuedHandling<TState extends s.IState> { | ||
interface IQueuedHandling<TState extends s.IState | null> { | ||
cursor: s.ICursor<TState>; | ||
@@ -111,4 +111,4 @@ handler: IInternalActionHandler<TState>; | ||
let queueOfHandlers: IQueuedHandling<s.IState>[] = []; | ||
function changeStateWithQueue<TState extends s.IState>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
let queueOfHandlers: IQueuedHandling<s.IState | null>[] = []; | ||
function changeStateWithQueue<TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
: boolean { | ||
@@ -136,3 +136,3 @@ queueOfHandlers.push({ cursor, handler }); | ||
function changeState<TState extends s.IState>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
function changeState<TState extends s.IState | null>(cursor: s.ICursor<TState>, handler: IInternalActionHandler<TState>) | ||
: boolean { | ||
@@ -139,0 +139,0 @@ let oldState = s.getState(cursor); |
241635