Esanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/382485 )

Change subject: Cleanup target teardown API
......................................................................

Cleanup target teardown API

Separate teardown from destroy, as MW targets do the former
but no the latter. Allow teardown methods to be async.

Change-Id: I9d97614695272dca6936ef6f3461178fcf0368a8
---
M src/init/ve.init.Target.js
1 file changed, 20 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/85/382485/1

diff --git a/src/init/ve.init.Target.js b/src/init/ve.init.Target.js
index 1dea3e9..1e2c0e1 100644
--- a/src/init/ve.init.Target.js
+++ b/src/init/ve.init.Target.js
@@ -288,14 +288,26 @@
 };
 
 /**
+ * Teardown the target, removing all surfaces, toolbars and handlers
+ *
+ * @return {jQuery.Promise} Promise which resolves when the target has been 
torn down
+ */
+ve.init.Target.prototype.teardown = function () {
+       this.unbindHandlers();
+       // Wait for the toolbar to teardown before clearing surfaces,
+       // as it may want to transition away
+       return this.teardownToolbar().then( this.clearSurfaces.bind( this ) );
+};
+
+/**
  * Destroy the target
  */
 ve.init.Target.prototype.destroy = function () {
-       this.clearSurfaces();
-       this.teardownToolbar();
-       this.$element.remove();
-       this.unbindHandlers();
-       ve.init.target = null;
+       var target = this;
+       this.teardown().then( function () {
+               target.$element.remove();
+               ve.init.target = null;
+       } );
 };
 
 /**
@@ -524,6 +536,8 @@
 
 /**
  * Teardown the toolbar
+ *
+ * @return {jQuery.Promise} Promise which resolves when the toolbar has been 
torn down
  */
 ve.init.Target.prototype.teardownToolbar = function () {
        if ( this.toolbar ) {
@@ -534,6 +548,7 @@
                this.actionsToolbar.destroy();
                this.actionsToolbar = null;
        }
+       return $.Deferred().resolve().promise();
 };
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/382485
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d97614695272dca6936ef6f3461178fcf0368a8
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to