Page MenuHomePhabricator

OOjs: EventEmitter#disconnect shouldn't throw if there are no bindings
Closed, DeclinedPublic

Description

surface.disconnect( this, { 'toolbarPosition': 'positionPhantoms' } );
This throws Uncaught TypeError: Cannot read property 'length' of undefined when no such event has been bound first.

oo.EventEmitter.prototype.disconnect = function ( context, methods ) {

/* .. */
    for ( event in methods ) {
        method = methods[event];
        /* .. */
        bindings = this.bindings[event];
        i = bindings.length; /* ! */

It should silently skip it.


Moved from https://github.com/trevorparscal/oojs/issues/18.


Version: unspecified
Severity: major

Details

Reference
bz57037

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 2:38 AM
bzimport set Reference to bz57037.

The no-op feature to allow calling disconnect() when no events are bound yet already exists. Change Ibe1d4747c05 adds tests to reflect this.

However when passing a host object that not only contains event handlers for events not (yet) bound, but explicitly specifying methods to unbind, then those methods have to exist (it's fine if they aren't bound as listeners, but they have to exist).