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 11import { Event , AppDispatcher } from '../dispatcher/AppDispatcher' ;
22import GreetingActionTypes from '../constants/action-types/GreetingActionTypes' ;
33
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+
48export function addGreeting ( newGreeting : string ) {
59 AppDispatcher . dispatch ( {
610 payload : newGreeting ,
711 type : GreetingActionTypes . ADD_GREETING
8- } ) ;
12+ } as AddGreetingEvent ) ;
913}
1014
1115export function newGreetingChanged ( newGreeting : string ) {
1216 AppDispatcher . dispatch ( {
1317 payload : newGreeting ,
1418 type : GreetingActionTypes . NEW_GREETING_CHANGED
15- } ) ;
19+ } as NewGreetingChanged ) ;
1620}
1721
1822export function removeGreeting ( greetingToRemove : string ) {
1923 AppDispatcher . dispatch ( {
2024 payload : greetingToRemove ,
2125 type : GreetingActionTypes . REMOVE_GREETING
22- } ) ;
26+ } as RemoveGreeting ) ;
2327}
Original file line number Diff line number Diff line change @@ -2,22 +2,26 @@ import FluxStore from './FluxStore';
22import GreetingActionTypes from '../constants/action-types/GreetingActionTypes' ;
33import { Event , AppDispatcher } from '../dispatcher/AppDispatcher' ;
44import GreetingState from '../types/GreetingState' ;
5+ import { AddGreetingEvent , RemoveGreeting , NewGreetingChanged } from '../actions/GreetingActions' ;
56
67class GreeterStore extends FluxStore < GreetingState > {
78 constructor ( dispatcher : Flux . Dispatcher < Event > ) {
89 const onDispatch = ( action : Event ) => {
910 switch ( action . type ) {
1011 case GreetingActionTypes . ADD_GREETING :
12+ let payload1 = ( < AddGreetingEvent > action ) . payload ;
1113 this . _state . newGreeting = '' ;
12- this . _state . greetings = this . _state . greetings . concat ( action . payload ) ;
14+ this . _state . greetings = this . _state . greetings . concat ( payload1 ) ;
1315 this . emitChange ( ) ;
1416 break ;
1517 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 ) ;
1720 this . emitChange ( ) ;
1821 break ;
1922 case GreetingActionTypes . NEW_GREETING_CHANGED :
20- this . _state . newGreeting = action . payload ;
23+ let payload3 = ( < NewGreetingChanged > action ) . payload ;
24+ this . _state . newGreeting = payload3 ;
2125 this . emitChange ( ) ;
2226 break ;
2327 }
You can’t perform that action at this time.
0 commit comments