From 18d2dd2d8051efff28b4562a55bb51565c3dc78d Mon Sep 17 00:00:00 2001 From: Cristina Hanes Date: Fri, 17 Apr 2015 14:49:40 -0700 Subject: [PATCH] Destroy jstree on willDestroyElement. Send eventDidDestroy. --- README.md | 13 +++++++------ addon/components/ember-jstree.js | 6 +++++- addon/mixins/ember-jstree-actions.js | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2a84dd4..3d47008 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,13 @@ in your controller. The following events have basic support included. More are on the way. -| jsTree Event | Ember Action | -|----------------|---------------------| -| changed.jstree | eventDidChange | -| init.jstree | eventDidInit | -| ready.jstree | eventDidBecomeReady | -| redraw.jstree | eventDidRedraw | +| jsTree Event | Ember Action | +|------------------------|-----------------------| +| changed.jstree | eventDidChange | +| init.jstree | eventDidInit | +| ready.jstree | eventDidBecomeReady | +| redraw.jstree | eventDidRedraw | +| (destroyed - no event) | eventDidDestroy | **Note:** In the meantime, you can add event listeners yourself by calling them on a mapped `treeObject` property. diff --git a/addon/components/ember-jstree.js b/addon/components/ember-jstree.js index 1bf5e42..e39301c 100644 --- a/addon/components/ember-jstree.js +++ b/addon/components/ember-jstree.js @@ -32,6 +32,10 @@ export default Ember.Component.extend(InboundActions, EmberJstreeActions, { this.set('treeObject', treeObject); }, + willDestroyElement: function() { + this.send('destroy'); + }, + searchCallback: function(str, node) { if(typeof node.original === 'object') { if(node.original[this.search_property]) { @@ -110,7 +114,7 @@ export default Ember.Component.extend(InboundActions, EmberJstreeActions, { _setupContextMenus: function(pluginsArray) { var contextmenuOptions = this.get('contextmenuOptions'); var self = this; - + if (null === pluginsArray) { return; } diff --git a/addon/mixins/ember-jstree-actions.js b/addon/mixins/ember-jstree-actions.js index 24d8cda..8eb79a6 100644 --- a/addon/mixins/ember-jstree-actions.js +++ b/addon/mixins/ember-jstree-actions.js @@ -23,6 +23,7 @@ export default Ember.Mixin.create({ var o = this.get('treeObject'); if (null !== o) { o.jstree(true).destroy(); + this.sendAction('eventDidDestroy'); } },