11import { Subject } from 'rxjs'
2- import { pick , mapValues } from 'lodash'
32
43import {
54 OriginalDefineActions ,
65 OriginalEffectActions ,
76 OriginalReducerActions ,
87 OriginalImmerReducerActions ,
8+ ConstructorOf ,
99} from '../types'
1010import { Ayanami } from '../ayanami'
1111import { getActionNames } from '../decorators'
1212import { effectSymbols , reducerSymbols , immerReducerSymbols , defineActionSymbols } from '../symbols'
1313
1414const getOriginalFunctionNames = ( ayanami : Ayanami < any > ) => ( {
15- effects : getActionNames ( effectSymbols , ayanami . constructor ) ,
16- reducers : getActionNames ( reducerSymbols , ayanami . constructor ) ,
17- defineActions : getActionNames ( defineActionSymbols , ayanami . constructor ) ,
18- immerReducers : getActionNames ( immerReducerSymbols , ayanami . constructor ) ,
15+ effects : getActionNames ( effectSymbols , ayanami . constructor as ConstructorOf < Ayanami < any > > ) ,
16+ reducers : getActionNames ( reducerSymbols , ayanami . constructor as ConstructorOf < Ayanami < any > > ) ,
17+ defineActions : getActionNames ( defineActionSymbols , ayanami . constructor as ConstructorOf <
18+ Ayanami < any >
19+ > ) ,
20+ immerReducers : getActionNames ( immerReducerSymbols , ayanami . constructor as ConstructorOf <
21+ Ayanami < any >
22+ > ) ,
1923} )
2024
2125const transformDefineActions = ( actionNames : string [ ] ) : OriginalDefineActions => {
@@ -37,15 +41,18 @@ export const getOriginalFunctions = (ayanami: Ayanami<any>) => {
3741 const { effects, reducers, immerReducers, defineActions } = getOriginalFunctionNames ( ayanami )
3842
3943 return {
40- effects : mapValues ( pick ( ayanami , effects ) , ( func : Function ) =>
41- func . bind ( ayanami ) ,
42- ) as OriginalEffectActions < any > ,
43- reducers : mapValues ( pick ( ayanami , reducers ) , ( func : Function ) =>
44- func . bind ( ayanami ) ,
45- ) as OriginalReducerActions < any > ,
46- immerReducers : mapValues ( pick ( ayanami , immerReducers ) , ( func : Function ) =>
47- func . bind ( ayanami ) ,
48- ) as OriginalImmerReducerActions < any > ,
44+ effects : effects . reduce < OriginalEffectActions < any > > ( ( acc , method ) => {
45+ acc [ method ] = ayanami [ method ] . bind ( ayanami )
46+ return acc
47+ } , { } ) ,
48+ reducers : reducers . reduce < OriginalReducerActions < any > > ( ( acc , method ) => {
49+ acc [ method ] = ayanami [ method ] . bind ( ayanami )
50+ return acc
51+ } , { } ) ,
52+ immerReducers : immerReducers . reduce < OriginalImmerReducerActions < any > > ( ( acc , method ) => {
53+ acc [ method ] = ayanami [ method ] . bind ( ayanami )
54+ return acc
55+ } , { } ) ,
4956 defineActions : transformDefineActions ( defineActions ) ,
5057 }
5158}
0 commit comments