Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with Glimmer 2 #37

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions addon/components/ember-tether.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ export default Component.extend({

willDestroyElement() {
this._super(...arguments);
let { _tether, element } = this;
run.schedule('render', () => {
this.removeElement(element);
this.removeTether(_tether);
});
const { _tether, element } = this;
this.removeTether(_tether);
this.moveElementBackIntoParent(element);
},

didRender() {
Expand Down Expand Up @@ -65,6 +63,12 @@ export default 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());
}
},
Expand All @@ -75,10 +79,14 @@ export default 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() {
Expand Down