0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Add Squire#destroy method.

Unbinds all event handlers to ensure no memory leaks.
This commit is contained in:
Neil Jenkins 2014-10-02 12:06:17 +07:00
parent d21ae23215
commit 6080cbf819
3 changed files with 30 additions and 2 deletions

View file

@ -1326,6 +1326,20 @@ proto.fireEvent = function ( type, event ) {
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 ) {
this.fireEvent( event.type, event );
};

File diff suppressed because one or more lines are too long

View file

@ -209,6 +209,20 @@ proto.fireEvent = function ( type, event ) {
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 ) {
this.fireEvent( event.type, event );
};