Skip to content

Commit

Permalink
fix: was doubling up on writes to drake.models, causing sometimes wro…
Browse files Browse the repository at this point in the history
…ng model order

fixes #878, hopefully.
  • Loading branch information
cormacrelf committed Jul 25, 2018
1 parent 59783f0 commit f1b26cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
11 changes: 4 additions & 7 deletions modules/ng2-dragula/src/components/dragula.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ export class DragulaDirective implements OnChanges, OnDestroy {

private subs: Subscription;

private container: any;
private get container(): HTMLElement {
return this.el && this.el.nativeElement;
}
private group: Group;

private el: ElementRef;
private dragulaService: DragulaService;
public constructor(el: ElementRef, dragulaService: DragulaService) {
this.el = el;
this.dragulaService = dragulaService;
this.container = el.nativeElement;
public constructor(private el: ElementRef, private dragulaService: DragulaService) {
}

public ngOnChanges(changes: {dragula?: SimpleChange, dragulaModel?: SimpleChange}): void {
Expand Down
4 changes: 0 additions & 4 deletions modules/ng2-dragula/src/components/dragula.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export class DragulaService {
let sourceModel = drake.models[drake.containers.indexOf(source)];
sourceModel = sourceModel.slice(0); // clone it
const item = sourceModel.splice(dragIndex, 1)[0];
drake.models[drake.containers.indexOf(source)] = sourceModel;
// console.log('REMOVE');
// console.log(sourceModel);
this.dispatch$.next({
Expand Down Expand Up @@ -196,7 +195,6 @@ export class DragulaService {
sourceModel = sourceModel.slice(0)
item = sourceModel.splice(dragIndex, 1)[0];
sourceModel.splice(dropIndex, 0, item);
drake.models[drake.containers.indexOf(source)] = sourceModel;
// this was true before we cloned and updated sourceModel,
// but targetModel still has the old value
targetModel = sourceModel;
Expand All @@ -216,8 +214,6 @@ export class DragulaService {
}
targetModel = targetModel.slice(0)
targetModel.splice(dropIndex, 0, item);
drake.models[drake.containers.indexOf(source)] = sourceModel;
drake.models[drake.containers.indexOf(target)] = targetModel;
if (isCopying) {
try {
target.removeChild(dropElm);
Expand Down

0 comments on commit f1b26cd

Please # to comment.