Exposed Evented#_hooksEvent as public #hooksEvent
parent
66e3d5b1ef
commit
eeea892967
|
@ -193,7 +193,7 @@ module.exports = Trait( 'Evented',
|
||||||
else if ( typeof listener !== 'function' ) {
|
else if ( typeof listener !== 'function' ) {
|
||||||
throw TypeError( "Event listener must be a function" );
|
throw TypeError( "Event listener must be a function" );
|
||||||
}
|
}
|
||||||
else if ( this._hooksEvent( ev, listener ) )
|
else if ( this.hooksEvent( ev, listener ) )
|
||||||
{
|
{
|
||||||
throw Error(
|
throw Error(
|
||||||
`Listener has already been bound to event \`${ev}'`
|
`Listener has already been bound to event \`${ev}'`
|
||||||
|
@ -260,10 +260,10 @@ module.exports = Trait( 'Evented',
|
||||||
*
|
*
|
||||||
* @return {boolean} whether LISTENER hooks event EV
|
* @return {boolean} whether LISTENER hooks event EV
|
||||||
*/
|
*/
|
||||||
_hooksEvent( ev, listener )
|
hooksEvent( ev, listener )
|
||||||
{
|
{
|
||||||
let levdata = listener[ _evid ];
|
let levdata = listener[ _evid ];
|
||||||
return ( levdata && ( levdata[ ev ] !== undefined ) );
|
return !!( levdata && ( levdata[ ev ] !== undefined ) );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -597,5 +597,54 @@ 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;
|
||||||
|
} );
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue