Skip to content

Commit

Permalink
immutable - Simplify moving from lane to another
Browse files Browse the repository at this point in the history
  • Loading branch information
bebraw committed Mar 8, 2016
1 parent 67e6502 commit 1366a5c
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions immutable_app/app/reducers/lanes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,14 @@ export default function lanes(state = initialState, action) {
return state.map((lane) => {
if(lane === sourceLane) {
// get rid of the source note
return Map(Object.assign({}, lane, {
notes: lane.get('notes').count() > 1 ? List(lane.get('notes').slice(0, sourceNoteIndex).concat(
lane.get('notes').slice(sourceNoteIndex + 1)
)): List()
}));
return lane.deleteIn(['notes', sourceNoteIndex]);
}

if(lane === targetLane) {
// and move it to target
return Map(Object.assign({}, lane, {
notes: List(lane.get('notes').slice(0, targetNoteIndex).concat(
[sourceId]
).concat(
lane.get('notes').slice(targetNoteIndex)
))
}));
return lane.updateIn(['notes'], notes => notes.insert(
targetNoteIndex, sourceId
));
}

return lane;
Expand Down

0 comments on commit 1366a5c

Please sign in to comment.