From f1b26cdcfa3a19dcb7999d57d2eeda82a45feb17 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Wed, 25 Jul 2018 19:31:05 +1000 Subject: [PATCH] fix: was doubling up on writes to drake.models, causing sometimes wrong model order fixes #878, hopefully. --- .../ng2-dragula/src/components/dragula.directive.ts | 11 ++++------- modules/ng2-dragula/src/components/dragula.service.ts | 4 ---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/modules/ng2-dragula/src/components/dragula.directive.ts b/modules/ng2-dragula/src/components/dragula.directive.ts index c65af526..88ad8ccd 100644 --- a/modules/ng2-dragula/src/components/dragula.directive.ts +++ b/modules/ng2-dragula/src/components/dragula.directive.ts @@ -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 { diff --git a/modules/ng2-dragula/src/components/dragula.service.ts b/modules/ng2-dragula/src/components/dragula.service.ts index 41b060b5..d01a16d4 100644 --- a/modules/ng2-dragula/src/components/dragula.service.ts +++ b/modules/ng2-dragula/src/components/dragula.service.ts @@ -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({ @@ -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; @@ -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);