From c8bddfbaeb9da205d6adede0fb877478cd6a3444 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 6 Aug 2014 00:11:25 -0400 Subject: [PATCH] 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. --- src/event/Eventable.js | 21 ----------------- src/event/Evented.js | 2 +- test/event/EventedTest.js | 49 --------------------------------------- 3 files changed, 1 insertion(+), 71 deletions(-) diff --git a/src/event/Eventable.js b/src/event/Eventable.js index e002ec0..d2d42cc 100644 --- a/src/event/Eventable.js +++ b/src/event/Eventable.js @@ -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 diff --git a/src/event/Evented.js b/src/event/Evented.js index 9ff96b5..532c472 100644 --- a/src/event/Evented.js +++ b/src/event/Evented.js @@ -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 ) ); diff --git a/test/event/EventedTest.js b/test/event/EventedTest.js index 34be455..622b232 100644 --- a/test/event/EventedTest.js +++ b/test/event/EventedTest.js @@ -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', () => { /**