Skip to content

Commit

Permalink
Fix action mutation with extra properties
Browse files Browse the repository at this point in the history
  • Loading branch information
svagi committed Oct 17, 2017
1 parent f119251 commit a80ea89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export function prefixType (prefix, type) {
}

export function createAction (type, payload, ...args) {
return Object.assign(...args, {
type: type,
payload: payload
})
return Object.assign({}, ...args, { type: type, payload: payload })
}

export function createRoutine (prefix, enhancer = identity) {
Expand Down
8 changes: 8 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ describe('createAction', () => {
test: true
})
})
it('should not mutate action with additional properties', () => {
const type = 'TEST'
const props = { test: true }
const action1 = createAction('type1', null, props)
const action2 = createAction('type2', null, props)
expect(action1.type).toContain('type1')
expect(action2.type).toContain('type2')
})
})

describe('prefixType', () => {
Expand Down

0 comments on commit a80ea89

Please sign in to comment.