mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-08 16:00:06 -05:00
Add Squire#destroy method.
Unbinds all event handlers to ensure no memory leaks.
This commit is contained in:
parent
d21ae23215
commit
6080cbf819
3 changed files with 30 additions and 2 deletions
|
@ -1326,6 +1326,20 @@ proto.fireEvent = function ( type, event ) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto.destroy = function () {
|
||||||
|
var win = this._win,
|
||||||
|
doc = this._doc,
|
||||||
|
events = this._events,
|
||||||
|
type;
|
||||||
|
win.removeEventListener( 'focus', this, false );
|
||||||
|
win.removeEventListener( 'blur', this, false );
|
||||||
|
for ( type in events ) {
|
||||||
|
if ( !customEvents[ type ] ) {
|
||||||
|
doc.removeEventListener( type, this, false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
proto.handleEvent = function ( event ) {
|
proto.handleEvent = function ( event ) {
|
||||||
this.fireEvent( event.type, event );
|
this.fireEvent( event.type, event );
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -209,6 +209,20 @@ proto.fireEvent = function ( type, event ) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto.destroy = function () {
|
||||||
|
var win = this._win,
|
||||||
|
doc = this._doc,
|
||||||
|
events = this._events,
|
||||||
|
type;
|
||||||
|
win.removeEventListener( 'focus', this, false );
|
||||||
|
win.removeEventListener( 'blur', this, false );
|
||||||
|
for ( type in events ) {
|
||||||
|
if ( !customEvents[ type ] ) {
|
||||||
|
doc.removeEventListener( type, this, false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
proto.handleEvent = function ( event ) {
|
proto.handleEvent = function ( event ) {
|
||||||
this.fireEvent( event.type, event );
|
this.fireEvent( event.type, event );
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue