Last active
May 28, 2016 12:40
-
-
Save stegrams/3efed9ff83853da9af8bc4778fcc9814 to your computer and use it in GitHub Desktop.
Lane action in LaneStore for dragging a note over a note or an empy lane instead of attachToLane. Source: http://survivejs.com/webpack_react/implementing_dnd/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
move({sourceId, targetId}){ | |
const lanes = []; | |
let sourceCheck, targetCheck; | |
for(let lane of this.lanes){ | |
if (sourceCheck && targetCheck) { | |
lanes.push(lane); | |
continue; | |
} | |
const notes = []; | |
lanes.push({...lane, notes}); | |
if (lane.id === targetId) { | |
if(lane.notes.length) return; | |
notes.push(sourceId); | |
targetCheck = true; | |
continue; | |
} | |
for(let note of lane.notes){ | |
switch(note){ | |
case sourceId: | |
sourceCheck = true; | |
break; | |
case targetId: | |
if(sourceCheck){ | |
notes.push(targetId, sourceId); | |
} else { | |
notes.push(sourceId, targetId); | |
} | |
targetCheck = true; | |
break; | |
default: | |
notes.push(note); | |
break; | |
} | |
} | |
} | |
this.setState({lanes}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment