Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 4935670

Browse files
committed
add payload types
1 parent 4d7b2c1 commit 4935670

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import {Event, AppDispatcher} from '../dispatcher/AppDispatcher';
22
import 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+
48
export function addGreeting(newGreeting: string) {
59
AppDispatcher.dispatch({
610
payload: newGreeting,
711
type: GreetingActionTypes.ADD_GREETING
8-
});
12+
} as AddGreetingEvent);
913
}
1014

1115
export function newGreetingChanged(newGreeting: string) {
1216
AppDispatcher.dispatch({
1317
payload: newGreeting,
1418
type: GreetingActionTypes.NEW_GREETING_CHANGED
15-
});
19+
} as NewGreetingChanged);
1620
}
1721

1822
export function removeGreeting(greetingToRemove: string) {
1923
AppDispatcher.dispatch({
2024
payload: greetingToRemove,
2125
type: GreetingActionTypes.REMOVE_GREETING
22-
});
26+
} as RemoveGreeting);
2327
}

react-with-type-safe-flux/src/stores/GreetingStore.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ import FluxStore from './FluxStore';
22
import GreetingActionTypes from '../constants/action-types/GreetingActionTypes';
33
import {Event, AppDispatcher} from '../dispatcher/AppDispatcher';
44
import GreetingState from '../types/GreetingState';
5+
import { AddGreetingEvent, RemoveGreeting, NewGreetingChanged } from '../actions/GreetingActions';
56

67
class 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
}

0 commit comments

Comments
 (0)