File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -307,4 +307,23 @@ describe('Window', () => {
307
307
expect ( childWindow . parent ) . toBe ( null ) ;
308
308
childWindow . destroy ( ) ;
309
309
} ) ;
310
+
311
+ test ( 'Should block destruction' , ( ) => {
312
+ const blockWindow = new Window ( core , {
313
+ ondestroy : ( ) => false
314
+ } ) ;
315
+
316
+ const noblockWindow = new Window ( core , {
317
+ ondestroy : ( ) => true
318
+ } ) ;
319
+
320
+ const defaultWindow = new Window ( core ) ;
321
+
322
+ blockWindow . destroy ( ) ;
323
+ noblockWindow . destroy ( ) ;
324
+ defaultWindow . destroy ( ) ;
325
+ expect ( blockWindow . destroyed ) . toBe ( false ) ;
326
+ expect ( noblockWindow . destroyed ) . toBe ( true ) ;
327
+ expect ( defaultWindow . destroyed ) . toBe ( true ) ;
328
+ } ) ;
310
329
} ) ;
Original file line number Diff line number Diff line change @@ -155,6 +155,7 @@ export default class Window extends EventEmitter {
155
155
* @param {string } [options.icon] Window Icon
156
156
* @param {Window } [options.parent] The parent Window reference
157
157
* @param {string|Function } [options.template] The Window HTML template (or function with signature (el, win) for programatic construction)
158
+ * @param {Function } [options.ondestroy] A callback function when window destructs to interrupt the procedure
158
159
* @param {WindowPosition|string } [options.position] Window position
159
160
* @param {WindowDimension } [options.dimension] Window dimension
160
161
* @param {WindowAttributes } [options.attributes] Apply Window attributes
@@ -166,6 +167,7 @@ export default class Window extends EventEmitter {
166
167
title : null ,
167
168
parent : null ,
168
169
template : null ,
170
+ ondestroy : null ,
169
171
attributes : { } ,
170
172
position : { } ,
171
173
dimension : { } ,
@@ -285,6 +287,12 @@ export default class Window extends EventEmitter {
285
287
*/
286
288
this . _template = options . template ;
287
289
290
+ /**
291
+ * Custom destructor callback
292
+ * @type {Function }
293
+ */
294
+ this . _ondestroy = options . ondestroy || ( ( ) => true ) ;
295
+
288
296
windows . push ( this ) ;
289
297
}
290
298
@@ -295,6 +303,11 @@ export default class Window extends EventEmitter {
295
303
if ( this . destroyed ) {
296
304
return ;
297
305
}
306
+
307
+ if ( typeof this . _ondestroy === 'function' && this . _ondestroy ( ) === false ) {
308
+ return ;
309
+ }
310
+
298
311
this . destroyed = true ;
299
312
300
313
logger . debug ( 'Window::destroy()' ) ;
You can’t perform that action at this time.
0 commit comments