File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed
Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import isPlainObject from 'lodash.isplainobject';
44describe ( 'createAction()' , ( ) => {
55 describe ( 'resulting action creator' , ( ) => {
66 const type = 'TYPE' ;
7- const actionCreator = createAction ( type , b => b ) ;
8- const foobar = { foo : 'bar' } ;
7+ const actionCreator = createAction ( type , b => b , ( { cid } ) => ( { cid } ) ) ;
8+ const foobar = { foo : 'bar' , cid : 5 } ;
99 const action = actionCreator ( foobar ) ;
1010
1111 it ( 'returns plain object' , ( ) => {
@@ -19,14 +19,18 @@ describe('createAction()', () => {
1919 it ( 'has no extraneous keys' , ( ) => {
2020 expect ( action ) . to . deep . equal ( {
2121 type,
22- payload : foobar
22+ payload : foobar ,
23+ meta : {
24+ cid : 5
25+ }
2326 } ) ;
2427 } ) ;
2528
26- it ( 'uses identity function if actionCreator is not a function' , ( ) => {
29+ it ( 'uses identity function if actionCreator and/or metaCreator is not a function' , ( ) => {
2730 expect ( createAction ( type ) ( foobar ) ) . to . deep . equal ( {
2831 type,
29- payload : foobar
32+ payload : foobar ,
33+ meta : foobar
3034 } ) ;
3135 } ) ;
3236 } ) ;
Original file line number Diff line number Diff line change @@ -2,13 +2,18 @@ function identity(t) {
22 return t ;
33}
44
5- export default function createAction ( type , actionCreator ) {
5+ export default function createAction ( type , actionCreator , metaCreator ) {
66 const finalActionCreator = typeof actionCreator === 'function'
77 ? actionCreator
88 : identity ;
99
10+ const finalMetaCreator = typeof metaCreator === 'function'
11+ ? metaCreator
12+ : identity ;
13+
1014 return ( ...args ) => ( {
1115 type,
12- payload : finalActionCreator ( ...args )
16+ payload : finalActionCreator ( ...args ) ,
17+ meta : finalMetaCreator ( ...args )
1318 } ) ;
1419}
You can’t perform that action at this time.
0 commit comments