Skip to content

Commit e5fdadf

Browse files
committed
Fixing mutation issue, adding inverse settings for isPlaying and isPaused
1 parent 0f0ffe8 commit e5fdadf

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

app/reducers/playback.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ const initialState = {
1111
export function setPlaybackState(state = initialState, action) {
1212
switch (action.type) {
1313
case IS_PLAYING :
14-
return Object.assign(state, {
15-
isPlaying: action.isPlaying
14+
return Object.assign({}, state, {
15+
isPlaying: action.isPlaying,
16+
isPaused: !action.isPlaying
1617
});
1718
case IS_PAUSED :
18-
return Object.assign(state, {
19+
return Object.assign({}, state, {
20+
isPlaying: !action.isPaused,
1921
isPaused: action.isPaused
2022
});
2123
default:

test/reducers/playback.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ describe('playbackState', () => {
1111
assert.strictEqual(playbackReducer(undefined, '').isPlaying, false);
1212
});
1313

14-
it('sets the property to true when passed in an isPlaying action with isPlaying set to true', () => {
15-
assert.strictEqual(playbackReducer(undefined, {
14+
it('{isPlaying: true, isPaused: false} when isPlaying is true', () => {
15+
const state = playbackReducer(undefined, {
1616
type: IS_PLAYING,
1717
isPlaying: true
18-
}).isPlaying, true);
18+
});
19+
assert.strictEqual(state.isPlaying, true);
20+
assert.strictEqual(state.isPaused, false);
1921
});
2022

21-
it('sets the property to false when passed in an isPlaying action with isPlaying set to false', () => {
22-
assert.strictEqual(playbackReducer(undefined, {
23+
it('{isPlaying: false, isPaused: true} when isPlaying is false', () => {
24+
const state = playbackReducer(undefined, {
2325
type: IS_PLAYING,
2426
isPlaying: false
25-
}).isPlaying, false);
27+
});
28+
assert.strictEqual(state.isPlaying, false);
29+
assert.strictEqual(state.isPaused, true);
2630
});
2731
});
2832

@@ -31,18 +35,22 @@ describe('playbackState', () => {
3135
assert.strictEqual(playbackReducer(undefined, '').isPaused, false);
3236
});
3337

34-
it('sets the property to true when passed in an isPaused action with isPaused set to true', () => {
35-
assert.strictEqual(playbackReducer(undefined, {
38+
it('{isPlaying: false, isPaused: true} when isPaused is true', () => {
39+
const state = playbackReducer(undefined, {
3640
type: IS_PAUSED,
3741
isPaused: true
38-
}).isPaused, true);
42+
});
43+
assert.strictEqual(state.isPaused, true);
44+
assert.strictEqual(state.isPlaying, false);
3945
});
4046

41-
it('sets the property to false when passed in an isPaused action with isPaused set to false', () => {
42-
assert.strictEqual(playbackReducer(undefined, {
47+
it('{isPlaying: true, isPaused: false} when isPaused is false', () => {
48+
const state = playbackReducer(undefined, {
4349
type: IS_PAUSED,
4450
isPaused: false
45-
}).isPaused, false);
51+
});
52+
assert.strictEqual(state.isPaused, false);
53+
assert.strictEqual(state.isPlaying, true);
4654
});
4755
});
4856
});

0 commit comments

Comments
 (0)