Skip to content

Commit

Permalink
add fix value
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgob committed Jun 14, 2016
1 parent 84c2995 commit cd4e0c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ export const utils = {


export const set = target => (state, action) => (setIn(state,target,action.payload ))
export const update = (target, updateCB) => (state, action) => (updateIn(state,target, (oldValue) => updateCB(oldValue, action.payload) ))
export const update = (target, updateCB) => (state, action) => {
let updateFinalCb;

if( typeof(updateCB) === 'function' )
updateFinalCb = (oldValue) => updateCB(oldValue, action.payload)
else
updateFinalCb = () => updateCB

return updateIn(state,target, updateFinalCb)
}

export const deepmerge = target => (state, action) => updateIn(state, target, (obj) => _deepmerge(obj, action.payload))
export const merge = target => (state, action) => updateIn(state, target, (obj) => ({...obj, ...action.payload}) )
export const remove = target => (state) => removeIn(state, target)
Expand Down
23 changes: 19 additions & 4 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('Test reduxit funcs', () => {


/* update */
it("update - ", () =>{
it("update - update collaback", () =>{
const action = {
type:'TYPE',
payload:5
Expand All @@ -235,10 +235,25 @@ describe('Test reduxit funcs', () => {
})
})

it("remove - ", () =>{
it("update - set fixed value", () =>{
const action = {
type:'TYPE',
payload:5
type:'TYPE'
}

update(['b','c'] , 'settedWithoutCallback' )(state,action)
.should.be.deep.equal({
a: "aa",
b: {
c:"settedWithoutCallback",
d: "dd"
}
})
})


it("remove - remove b.c", () =>{
const action = {
type:'TYPE'
}

remove(['b','c'])(state,action)
Expand Down

0 comments on commit cd4e0c8

Please sign in to comment.