Skip to content

Instantly share code, notes, and snippets.

@stegrams
Last active May 28, 2016 12:40
Show Gist options
  • Save stegrams/3efed9ff83853da9af8bc4778fcc9814 to your computer and use it in GitHub Desktop.
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/
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