Comparing version 4.1.0 to 4.2.0
CHANGELOG | ||
=== | ||
4.2.0 | ||
-- | ||
New Features | ||
- | ||
Actions in setter variant. Function createAction has a default handler working as setter. | ||
4.1.0 | ||
@@ -4,0 +13,0 @@ -- |
{ | ||
"name": "fun-model", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "fun-model is pure functional implementation of FLUX architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -199,2 +199,10 @@ "use strict"; | ||
}); | ||
it('uses action as simple setter when no handler defined', function () { | ||
givenStore(aState('nestedStateValue')); | ||
var testAction = af.createAction(NestedStateCursorTestFixture); | ||
testAction('nestedStateValue'); | ||
expect(renderCallback).not.toHaveBeenCalled(); | ||
testAction('newNestedStateValue'); | ||
expect(renderCallback).toHaveBeenCalled(); | ||
}); | ||
}); | ||
@@ -218,4 +226,7 @@ }); | ||
}; | ||
var NestedStateCursorTestFixture = { | ||
key: 'some.nested.state' | ||
}; | ||
var SomeCursorTestFixture = { | ||
key: 'some' | ||
}; |
@@ -256,2 +256,13 @@ import * as s from '../src/store'; | ||
}); | ||
it('uses action as simple setter when no handler defined', () => { | ||
givenStore(aState('nestedStateValue')); | ||
const testAction = af.createAction<string, string>(NestedStateCursorTestFixture); | ||
testAction('nestedStateValue'); | ||
expect(renderCallback).not.toHaveBeenCalled(); | ||
testAction('newNestedStateValue'); | ||
expect(renderCallback).toHaveBeenCalled(); | ||
}); | ||
}); | ||
@@ -290,4 +301,8 @@ }); | ||
var NestedStateCursorTestFixture: s.ICursor<string> = { | ||
key: 'some.nested.state' | ||
} | ||
var SomeCursorTestFixture: s.ICursor<ISomeState> = { | ||
key: 'some' | ||
} |
@@ -14,3 +14,5 @@ "use strict"; | ||
}; | ||
function defaultHandler(_oldValue, newValue) { return newValue; } | ||
exports.createAction = function (cursor, handler) { | ||
if (handler === void 0) { handler = defaultHandler; } | ||
return (function (params) { | ||
@@ -17,0 +19,0 @@ if (stateChanged === null) |
@@ -21,3 +21,5 @@ import * as s from './store'; | ||
export const createAction = <TState extends s.IState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>) | ||
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) | ||
: IAction<TParams> => { | ||
@@ -24,0 +26,0 @@ return <IAction<TParams>>((params?: TParams): void => { |
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
228854
1554