From b97373cc92926dba1d6174cdf5b4a120c02b890e Mon Sep 17 00:00:00 2001 From: Scott Messinger Date: Wed, 2 Nov 2016 21:49:28 -0400 Subject: [PATCH 1/3] Make compatible with Glimmer 2 Moves the element back into it's original parent so Glimmer 2's clean up code doesn't error out. --- addon/components/ember-tether.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/addon/components/ember-tether.js b/addon/components/ember-tether.js index 39b3bda..dcb59f0 100644 --- a/addon/components/ember-tether.js +++ b/addon/components/ember-tether.js @@ -22,10 +22,8 @@ export default Ember.Component.extend({ willDestroyElement() { this._super(...arguments); const { _tether, element } = this; - run.schedule('render', () => { - this.removeElement(element); - this.removeTether(_tether); - }); + this.removeTether(_tether); + this.moveElementBackIntoParent(element); }, didRender() { @@ -57,6 +55,12 @@ export default Ember.Component.extend({ addTether() { if (get(this, '_tetherTarget')) { + // Tether moves our element in the DOM. This + // causes Glimmer 2 to be very, very confused. + // So, we save the original parent which we'll + // append the element to after we remove tether in + // removeElement + this._originalParentNode = this.element.parentNode this._tether = new Tether(this._tetherOptions()); } }, @@ -67,10 +71,14 @@ export default Ember.Component.extend({ } }, - removeElement(element) { + moveElementBackIntoParent(element) { + // Remove the element from the body if (element.parentNode) { element.parentNode.removeChild(element); } + // For Glimmer 2 to work properly, we need to + // to readd the element to the original parent + this._originalParentNode.appendChild(element) }, _tetherTarget: computed('target', function() { From c77f9b8374be39ce21f7a6a70aefda9d389a4944 Mon Sep 17 00:00:00 2001 From: Scott Messinger Date: Wed, 2 Nov 2016 21:59:05 -0400 Subject: [PATCH 2/3] Fix whitespace and semicolons --- addon/components/ember-tether.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/components/ember-tether.js b/addon/components/ember-tether.js index dcb59f0..7f06018 100644 --- a/addon/components/ember-tether.js +++ b/addon/components/ember-tether.js @@ -55,12 +55,12 @@ export default Ember.Component.extend({ addTether() { if (get(this, '_tetherTarget')) { - // Tether moves our element in the DOM. This + // Tether moves our element in the DOM. This // causes Glimmer 2 to be very, very confused. // So, we save the original parent which we'll // append the element to after we remove tether in // removeElement - this._originalParentNode = this.element.parentNode + this._originalParentNode = this.element.parentNode; this._tether = new Tether(this._tetherOptions()); } }, @@ -78,7 +78,7 @@ export default Ember.Component.extend({ } // For Glimmer 2 to work properly, we need to // to readd the element to the original parent - this._originalParentNode.appendChild(element) + this._originalParentNode.appendChild(element); }, _tetherTarget: computed('target', function() { From 66ed5d4b9cd78d89f57f2a378f9b9d5d1b6edde7 Mon Sep 17 00:00:00 2001 From: Scott Messinger Date: Wed, 2 Nov 2016 22:01:36 -0400 Subject: [PATCH 3/3] Fix whitespace and unnecessary import --- addon/components/ember-tether.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/components/ember-tether.js b/addon/components/ember-tether.js index 7f06018..46a39fe 100644 --- a/addon/components/ember-tether.js +++ b/addon/components/ember-tether.js @@ -1,6 +1,6 @@ import Ember from 'ember'; -const { observer, get, run, computed } = Ember; +const { observer, get, computed } = Ember; export default Ember.Component.extend({ classNames: ['ember-tether'], @@ -76,7 +76,7 @@ export default Ember.Component.extend({ if (element.parentNode) { element.parentNode.removeChild(element); } - // For Glimmer 2 to work properly, we need to + // For Glimmer 2 to work properly, we need to // to readd the element to the original parent this._originalParentNode.appendChild(element); },