Slide 82
Slide 82 text
// Actions
export const FOLLOW_TOPIC = 'TOPICS/FOLLOW';
export const RECEIVE_TOPICS = 'TOPICS/RECEIVE';
export const UNFOLLOW_TOPIC = 'TOPICS/UNFOLLOW';
// Reducer
type TopicsState = Immutable.Map;
export const initialState: TopicsState = new Immutable.Map();
export default createReducer(initialState, {
[RECEIVE_TOPICS]: (state: TopicsState, action: Action): TopicsState => { /* ... */ },
[FOLLOW_TOPIC]: (state: TopicsState, action: Action): TopicsState => { /* ... */ },
[UNFOLLOW_TOPIC]: (state: TopicsState, action: Action): TopicsState => { /*...*/ },
});
// Action Creators
export function receiveTopic({ topic }: { topic: Topic }): Dispatchable {
return { type: RECEIVE_TOPICS, payload: { topics: [topic] } };
}
export function receiveTopics({ topics }: { topics: Array }): Dispatchable {
return { type: RECEIVE_TOPICS, payload: { topics } };
}
export function toggleTopicFollow(topicId: number): Dispatchable {
return function(dispatch: Dispatch, getState: Function, api: any): void {
const { currentUser } = getState();
if (isFollowingTopic(currentUser, id)) {