@@ -3,7 +3,7 @@ import 'reflect-metadata'
3
3
4
4
import { GLOBAL_KEY_SYMBOL , EffectModule , ImmerReducer , Module , Effect , Reducer , RETRY_KEY_SYMBOL } from '@sigi/core'
5
5
import { Injectable , Injector } from '@sigi/di'
6
- import { emitSSREffects } from '@sigi/ssr'
6
+ import { emitSSREffects , match } from '@sigi/ssr'
7
7
import { Action } from '@sigi/types'
8
8
import { Draft } from 'immer'
9
9
import { useEffect } from 'react'
@@ -700,4 +700,42 @@ describe('SSR specs:', () => {
700
700
InnerServiceModule : [ 'setNameWithFailure' ] ,
701
701
} )
702
702
} )
703
+
704
+ it ( 'should support match fn' , async ( ) => {
705
+ @Module ( 'InnerServiceModule2' )
706
+ class InnerServiceModule2 extends EffectModule < CountState > {
707
+ readonly defaultState = { count : 0 , name : '' }
708
+
709
+ @ImmerReducer ( )
710
+ setName ( state : Draft < CountState > , name : string ) {
711
+ state . name = name
712
+ }
713
+
714
+ @Effect ( {
715
+ payloadGetter : match (
716
+ [ '/users/:id' ] ,
717
+ ( ctx : any ) => ctx . request . path ,
718
+ ) ( ( ctx ) => {
719
+ return ctx . request . path . length
720
+ } ) ,
721
+ } )
722
+ setNameWithFailure ( payload$ : Observable < number > ) : Observable < Action > {
723
+ return payload$ . pipe ( mergeMap ( ( l ) => of ( this . getActions ( ) . setName ( `length: ${ l } ` ) , this . terminate ( ) ) ) )
724
+ }
725
+ }
726
+
727
+ const req = {
728
+ request : {
729
+ path : '/users/linus' ,
730
+ } ,
731
+ }
732
+ const state = await emitSSREffects ( req , [ InnerServiceModule2 ] , { providers : [ InnerServiceModule2 ] } ) . pendingState
733
+
734
+ expect ( state [ 'dataToPersist' ] ) . toEqual ( {
735
+ InnerServiceModule2 : {
736
+ count : 0 ,
737
+ name : `length: ${ req . request . path . length } ` ,
738
+ } ,
739
+ } )
740
+ } )
703
741
} )
0 commit comments