From ca2ce289aaa0d95f835d1f020121c12509b6f5fd Mon Sep 17 00:00:00 2001 From: Severin Opel Date: Tue, 30 Jul 2019 13:21:17 +0200 Subject: [PATCH] Improved scatter closing. Added module to eslint. --- .eslintrc | 3 ++- lib/scatter.js | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 1aa0400..290b33b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,8 @@ "ecmaVersion": 10, "sourceType": "module", "ecmaFeatures": { - "impliedStrict": true + "impliedStrict": true, + "modules": true } }, "env": { diff --git a/lib/scatter.js b/lib/scatter.js index 5357de1..b841647 100644 --- a/lib/scatter.js +++ b/lib/scatter.js @@ -370,15 +370,22 @@ export class AbstractScatter extends Throwable { } close() { + this._callCloseCallbacks() + this._removeSelfFromScatterContainer() + } + + _callCloseCallbacks() { if (this.onClose) { this.onClose.forEach(callback => callback(this)) + } + } - /** + _removeSelfFromScatterContainer() { + /** Removes self from container when it's closed. */ - if(this.container){ - this.container.remove(this) - } + if (this.container) { + this.container.remove(this) } } @@ -1007,17 +1014,22 @@ export class DOMScatterContainer { } } - /** * Removes an element from the scatter. * * @param {Scatter} scatter - Element to remove. * @memberof DOMScatterContainer */ - remove(scatter){ - this.scatter.delete(scatter.element) - } + remove(scatter) { + const element = scatter.element + if (!this.scatter.has(element)) + console.warn( + `Try removing element that is not in the scatter.`, + element + ) + this.scatter.delete(element) + } /** * Adds an element to the ScatterContainer.