From e7c1caf65e2678bc09faa2c61d6d3136b7334681 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Sun, 2 Dec 2018 16:05:51 +0200 Subject: [PATCH] move action type strings to constants --- src/actions/action_types.js | 3 +++ src/actions/fetchVideos.js | 5 +++-- src/actions/test.js | 4 +++- src/reducers/home.js | 7 ++++--- 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 src/actions/action_types.js diff --git a/src/actions/action_types.js b/src/actions/action_types.js new file mode 100644 index 0000000..c4e2cc7 --- /dev/null +++ b/src/actions/action_types.js @@ -0,0 +1,3 @@ +export const TEST_ACTION = 'TEST_ACTION'; +export const START_LOADING_VIDEOS = 'START_LOADING_VIDEOS'; +export const RECEIVE_VIDEOS = 'RECEIVE_VIDEOS'; diff --git a/src/actions/fetchVideos.js b/src/actions/fetchVideos.js index 3dd2ea0..789bf14 100644 --- a/src/actions/fetchVideos.js +++ b/src/actions/fetchVideos.js @@ -1,4 +1,5 @@ import config from '../config'; +import { START_LOADING_VIDEOS, RECEIVE_VIDEOS } from './action_types'; function fetchVideos() { console.log('fetchVideos called'); @@ -34,13 +35,13 @@ function fetchVideos() { function startLoadingVideos() { return { - type: 'START_LOADING_VIDEOS' + type: START_LOADING_VIDEOS } } function receiveVideos(videos) { return { - type: 'RECEIVE_VIDEOS', + type: RECEIVE_VIDEOS, payload: videos } } diff --git a/src/actions/test.js b/src/actions/test.js index 4e3aff1..aca0629 100644 --- a/src/actions/test.js +++ b/src/actions/test.js @@ -1,6 +1,8 @@ +import { TEST_ACTION } from './action_types'; + function testAction(data) { return { - type: 'TEST_ACTION', + type: TEST_ACTION, payload: data } } diff --git a/src/reducers/home.js b/src/reducers/home.js index 66aa6f5..15d9a1c 100644 --- a/src/reducers/home.js +++ b/src/reducers/home.js @@ -1,14 +1,15 @@ +import { TEST_ACTION, START_LOADING_VIDEOS, RECEIVE_VIDEOS } from '../actions/action_types'; export default function (state = {}, action) { switch (action.type) { - case 'TEST_ACTION': + case TEST_ACTION: return Object.assign({}, state, { test: action.payload }); - case 'START_LOADING_VIDEOS': + case START_LOADING_VIDEOS: return Object.assign({}, state, { loading: true }); - case 'RECEIVE_VIDEOS': + case RECEIVE_VIDEOS: return Object.assign({}, state, { loading: false, videos: action.payload }) }