Eventable and Evented no longer include #hooksEvent

This is introspection, which can be provided elsewhere or by specific
implementations. Together with the documented requirement (in Eventable#on)
that listeners must be notified of automatic un-hooking, and that systems
handling listeners will always be aware of when listeners are
hooked/unhooked, this method should not be necessary.

Including this method in Eventable also introduces incompatibility with
Node.js' Event API, which is undesirable.
events
Mike Gerwitz 2014-08-06 00:11:25 -04:00
parent 7fa2a296d2
commit c8bddfbaeb
3 changed files with 1 additions and 71 deletions

View File

@ -106,27 +106,6 @@ module.exports = Interface( 'Eventable',
addListener: [ 'ev', 'listener' ],
/**
* Determine whether LISTENER is listening for messages emitted by event
* EV
*
* If event EV is not valid, either `false` shall be returned or
* an error shall be thrown, since LISTENER cannot possibly hook an
* invalid event.
*
* This method is not intended as an introspective/reflection
* mechanism---it allows a consumer of an Eventable object to determine
* whether LISTENER has already been hooked before blindly
* hooking/unhooking it.
*
* @param {string} ev event id
* @param {Function} listener listener to query for
*
* @return {boolean} whether LISTENER hooks event EV
*/
hooksEvent: [ 'ev', 'listener' ],
/**
* Unhook LISTENER from event EV, preventing further messages from being
* received

View File

@ -296,7 +296,7 @@ module.exports = Trait( 'Evented' )
*
* @return {boolean} whether LISTENER hooks event EV
*/
hooksEvent( ev, listener )
'protected hooksEvent'( ev, listener )
{
let levdata = listener[ this._evid ];
return !!( levdata && ( levdata[ ev ] !== undefined ) );

View File

@ -617,55 +617,6 @@ describe( 'event.Evented', () =>
} );
describe( '#hooksEvent', () =>
{
var ev = 'foo',
f;
beforeEach( () =>
{
// ensure fresh listener
f = () => {};
} );
it( 'recognizes listener for a hooked event', () =>
{
stub.evDefineEvents( [ ev ] )
.on( ev, f );
expect( stub.hooksEvent( ev, f ) ).to.be.true;
} );
it( 'does not recognize listener for non-hooked event', () =>
{
expect( stub.hooksEvent( ev, f ) ).to.be.false;
} );
/**
* Technically this test is sufficient to make the previous two
* redundant, but they are retained for clairty in debugging.
*/
it( 'does not recognize listeners of other events', () =>
{
var ev2 = 'bar',
f2 = () => {};
stub.evDefineEvents( [ ev, ev2 ] )
.on( ev, f )
.on( ev2, f2 );
expect( stub.hooksEvent( ev, f ) ).to.be.true;
expect( stub.hooksEvent( ev2, f ) ).to.be.false;
expect( stub.hooksEvent( ev, f2 ) ).to.be.false;
expect( stub.hooksEvent( ev2, f2 ) ).to.be.true;
} );
} );
describe( 'listener metadata', () =>
{
/**