From 5bec6c275e5053b21dd109879f644f1e0a58cd9d Mon Sep 17 00:00:00 2001 From: Darmody Date: Fri, 1 Apr 2016 23:48:55 +0800 Subject: [PATCH] improve actions witch redux-actions --- src/reducers/__tests__/auth.spec.js | 2 +- src/reducers/__tests__/channel.spec.js | 4 ++-- src/reducers/__tests__/favorite.spec.js | 4 ++-- src/reducers/auth.js | 8 ++------ src/reducers/channel.js | 17 ++++------------- src/reducers/favorite.js | 24 +++++------------------- 6 files changed, 16 insertions(+), 43 deletions(-) diff --git a/src/reducers/__tests__/auth.spec.js b/src/reducers/__tests__/auth.spec.js index 55b6379..34ca9fe 100644 --- a/src/reducers/__tests__/auth.spec.js +++ b/src/reducers/__tests__/auth.spec.js @@ -107,7 +107,7 @@ describe('Auth Actions', function actions() { }); it('LOGOUT', function logoutSuccess() { - expect(logout()).to.deep.equal({ type: LOGOUT }); + expect(logout()).to.deep.equal({ type: LOGOUT, payload: undefined }); }); }); diff --git a/src/reducers/__tests__/channel.spec.js b/src/reducers/__tests__/channel.spec.js index f4d9f9f..d61c0f8 100644 --- a/src/reducers/__tests__/channel.spec.js +++ b/src/reducers/__tests__/channel.spec.js @@ -221,11 +221,11 @@ describe('Channel Actions', function actions() { }); it('PLAY', function playSuccess() { - expect(play()).to.deep.equal({ type: PLAY }); + expect(play()).to.deep.equal({ type: PLAY, payload: undefined }); }); it('PAUSE', function pauseSuccess() { - expect(pause()).to.deep.equal({ type: PAUSE }); + expect(pause()).to.deep.equal({ type: PAUSE, payload: undefined }); }); it('JUMP', function jumpSuccess() { diff --git a/src/reducers/__tests__/favorite.spec.js b/src/reducers/__tests__/favorite.spec.js index 5ef7400..b01c876 100644 --- a/src/reducers/__tests__/favorite.spec.js +++ b/src/reducers/__tests__/favorite.spec.js @@ -197,11 +197,11 @@ describe('Favorite Actions', function actions() { }); it('PLAY', function playSuccess() { - expect(play()).to.deep.equal({ type: PLAY }); + expect(play()).to.deep.equal({ type: PLAY, payload: undefined }); }); it('PAUSE', function pauseSuccess() { - expect(pause()).to.deep.equal({ type: PAUSE }); + expect(pause()).to.deep.equal({ type: PAUSE, payload: undefined }); }); it('NEXT', function nextSuccess() { diff --git a/src/reducers/auth.js b/src/reducers/auth.js index dd14f43..ec90a10 100644 --- a/src/reducers/auth.js +++ b/src/reducers/auth.js @@ -1,6 +1,6 @@ import Immutable from 'seamless-immutable'; import { CALL_API } from 'redux-api-middleware'; -import { handleActions } from 'redux-actions'; +import { createAction, handleActions } from 'redux-actions'; import _ from 'ramda'; import { VERIFY_REQUEST, VERIFY_SUCCESS, VERIFY_FAILURE, @@ -34,11 +34,7 @@ export default handleActions({ [VERIFY_FAILURE]: (state) => ({ ...state, user: initialState.user, }) }, initialState); -export function logout() { - return { - type: LOGOUT - }; -} +export const logout = createAction(LOGOUT); export function login(data) { const defaultParams = { diff --git a/src/reducers/channel.js b/src/reducers/channel.js index 905dc51..16c3a67 100644 --- a/src/reducers/channel.js +++ b/src/reducers/channel.js @@ -1,5 +1,5 @@ import Immutable from 'seamless-immutable'; -import { handleActions } from 'redux-actions'; +import { createAction, handleActions } from 'redux-actions'; import _apiMiddleware from '../utils/apiMiddleware'; import _song from '../modules/song'; import _ from 'ramda'; @@ -81,17 +81,8 @@ export function ban(channel, songId) { return _apiMiddleware.fetch(types, channel, songId, 'b'); } -export function jump(song) { - return { - type: JUMP, - payload: { song } - }; -} +export const jump = createAction(JUMP, song => ({ song })); -export function play() { - return { type: PLAY }; -} +export const play = createAction(PLAY); -export function pause() { - return { type: PAUSE }; -} +export const pause = createAction(PAUSE); diff --git a/src/reducers/favorite.js b/src/reducers/favorite.js index e4ec8f1..6262200 100644 --- a/src/reducers/favorite.js +++ b/src/reducers/favorite.js @@ -1,6 +1,6 @@ import Immutable from 'seamless-immutable'; import { CALL_API } from 'redux-api-middleware'; -import { handleActions } from 'redux-actions'; +import { createAction, handleActions } from 'redux-actions'; import _ from 'ramda'; import sample from 'lodash.sample'; import _apiMiddleware from '../utils/apiMiddleware'; @@ -105,12 +105,7 @@ export function fetchAll() { }; } -export function next(lastSongId) { - return { - type: NEXT, - payload: { lastSongId } - }; -} +export const next = createAction(NEXT, lastSongId => ({ lastSongId })); export function like(songId) { const types = () => ([LIKE_REQUEST, LIKE_SUCCESS, LIKE_FAILURE]); @@ -139,17 +134,8 @@ export function ban(songId) { return _apiMiddleware.fetch(types, 0, songId, 'b'); } -export function play() { - return { type: PLAY }; -} +export const play = createAction(PLAY); -export function pause() { - return { type: PAUSE }; -} +export const pause = createAction(PAUSE); -export function jump(song) { - return { - type: JUMP, - payload: { song } - }; -} +export const jump = createAction(JUMP, song => ({ song }));