Skip to content

Commit

Permalink
improve actions witch redux-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody committed Apr 1, 2016
1 parent 909998f commit 5bec6c2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/reducers/__tests__/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/reducers/__tests__/channel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/__tests__/favorite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 2 additions & 6 deletions src/reducers/auth.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
17 changes: 4 additions & 13 deletions src/reducers/channel.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
24 changes: 5 additions & 19 deletions src/reducers/favorite.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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 }));

0 comments on commit 5bec6c2

Please sign in to comment.