This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
react-with-type-safe-flux/src Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { Event , AppDispatcher } from '../dispatcher/AppDispatcher' ;
2
2
import GreetingActionTypes from '../constants/action-types/GreetingActionTypes' ;
3
3
4
+ export interface AddGreetingEvent { type : string ; payload : string ; }
5
+ export interface NewGreetingChanged { type : string ; payload : string ; }
6
+ export interface RemoveGreeting { type : string ; payload : string ; }
7
+
4
8
export function addGreeting ( newGreeting : string ) {
5
9
AppDispatcher . dispatch ( {
6
10
payload : newGreeting ,
7
11
type : GreetingActionTypes . ADD_GREETING
8
- } ) ;
12
+ } as AddGreetingEvent ) ;
9
13
}
10
14
11
15
export function newGreetingChanged ( newGreeting : string ) {
12
16
AppDispatcher . dispatch ( {
13
17
payload : newGreeting ,
14
18
type : GreetingActionTypes . NEW_GREETING_CHANGED
15
- } ) ;
19
+ } as NewGreetingChanged ) ;
16
20
}
17
21
18
22
export function removeGreeting ( greetingToRemove : string ) {
19
23
AppDispatcher . dispatch ( {
20
24
payload : greetingToRemove ,
21
25
type : GreetingActionTypes . REMOVE_GREETING
22
- } ) ;
26
+ } as RemoveGreeting ) ;
23
27
}
Original file line number Diff line number Diff line change @@ -2,22 +2,26 @@ import FluxStore from './FluxStore';
2
2
import GreetingActionTypes from '../constants/action-types/GreetingActionTypes' ;
3
3
import { Event , AppDispatcher } from '../dispatcher/AppDispatcher' ;
4
4
import GreetingState from '../types/GreetingState' ;
5
+ import { AddGreetingEvent , RemoveGreeting , NewGreetingChanged } from '../actions/GreetingActions' ;
5
6
6
7
class GreeterStore extends FluxStore < GreetingState > {
7
8
constructor ( dispatcher : Flux . Dispatcher < Event > ) {
8
9
const onDispatch = ( action : Event ) => {
9
10
switch ( action . type ) {
10
11
case GreetingActionTypes . ADD_GREETING :
12
+ let payload1 = ( < AddGreetingEvent > action ) . payload ;
11
13
this . _state . newGreeting = '' ;
12
- this . _state . greetings = this . _state . greetings . concat ( action . payload ) ;
14
+ this . _state . greetings = this . _state . greetings . concat ( payload1 ) ;
13
15
this . emitChange ( ) ;
14
16
break ;
15
17
case GreetingActionTypes . REMOVE_GREETING :
16
- this . _state . greetings = this . _state . greetings . filter ( g => g !== action . payload ) ;
18
+ let payload2 = ( < RemoveGreeting > action ) . payload ;
19
+ this . _state . greetings = this . _state . greetings . filter ( g => g !== payload2 ) ;
17
20
this . emitChange ( ) ;
18
21
break ;
19
22
case GreetingActionTypes . NEW_GREETING_CHANGED :
20
- this . _state . newGreeting = action . payload ;
23
+ let payload3 = ( < NewGreetingChanged > action ) . payload ;
24
+ this . _state . newGreeting = payload3 ;
21
25
this . emitChange ( ) ;
22
26
break ;
23
27
}
You can’t perform that action at this time.
0 commit comments