move action type strings to constants

This commit is contained in:
Sanjay Bhangar 2018-12-02 16:05:51 +02:00
parent 5517141edf
commit e7c1caf65e
4 changed files with 13 additions and 6 deletions

View File

@ -0,0 +1,3 @@
export const TEST_ACTION = 'TEST_ACTION';
export const START_LOADING_VIDEOS = 'START_LOADING_VIDEOS';
export const RECEIVE_VIDEOS = 'RECEIVE_VIDEOS';

View File

@ -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
}
}

View File

@ -1,6 +1,8 @@
import { TEST_ACTION } from './action_types';
function testAction(data) {
return {
type: 'TEST_ACTION',
type: TEST_ACTION,
payload: data
}
}

View File

@ -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 })
}