Skip to content

Commit a80ea89

Browse files
committed
Fix action mutation with extra properties
1 parent f119251 commit a80ea89

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ export function prefixType (prefix, type) {
1717
}
1818

1919
export function createAction (type, payload, ...args) {
20-
return Object.assign(...args, {
21-
type: type,
22-
payload: payload
23-
})
20+
return Object.assign({}, ...args, { type: type, payload: payload })
2421
}
2522

2623
export function createRoutine (prefix, enhancer = identity) {

src/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ describe('createAction', () => {
104104
test: true
105105
})
106106
})
107+
it('should not mutate action with additional properties', () => {
108+
const type = 'TEST'
109+
const props = { test: true }
110+
const action1 = createAction('type1', null, props)
111+
const action2 = createAction('type2', null, props)
112+
expect(action1.type).toContain('type1')
113+
expect(action2.type).toContain('type2')
114+
})
107115
})
108116

109117
describe('prefixType', () => {

0 commit comments

Comments
 (0)