MCPcopy Create free account
hub / github.com/LeetCode-OpenSource/ayanami / CountModel

Class CountModel

test/specs/ssr.spec.tsx:28–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28@SSRModule('CountModel')
29class CountModel extends Ayanami<CountState> {
30 defaultState = { count: 0, name: '' }
31
32 @ImmerReducer()
33 setCount(state: Draft<CountState>, count: number) {
34 state.count = count
35 }
36
37 @ImmerReducer()
38 setName(state: Draft<CountState>, name: string) {
39 state.name = name
40 }
41
42 @SSREffect()
43 getCount(payload$: Observable<void>): Observable<EffectAction> {
44 return payload$.pipe(
45 switchMap(() =>
46 timer(1).pipe(
47 map(() => this.getActions().setCount(1)),
48 endWith(TERMINATE_ACTION),
49 ),
50 ),
51 )
52 }
53
54 @SSREffect({
55 payloadGetter: (req, skip) => req.url || skip(),
56 skipFirstClientDispatch: false,
57 })
58 skippedEffect(payload$: Observable<string>): Observable<EffectAction> {
59 return payload$.pipe(
60 switchMap((name) =>
61 timer(1).pipe(
62 map(() => this.getActions().setName(name)),
63 endWith(TERMINATE_ACTION),
64 ),
65 ),
66 )
67 }
68}
69
70interface TipState {
71 tip: string

Callers

nothing calls this directly

Calls 2

SSRModuleFunction · 0.90
SSREffectFunction · 0.90

Tested by

no test coverage detected