THe max number of bits to check againts.
The default is 32 bits:
const emitter = new BitFieldEmitter<void>()
emitter.on(1 << 31, () => console.log('fired'))
emitter.emit(1 << 31) // fired
Passing less than the default results in some bits beeing ignored:
const emitter = new BitFieldEmitter<void>(31)
emitter.on(1 << 32, () => console.log('fired'))
emitter.emit(1 << 31) // nothing
Array of event handler sets. Initialized in the constructors.
THe max number of bits to check againts.
The default is 32 bits:
const emitter = new BitFieldEmitter<void>()
emitter.on(1 << 31, () => console.log('fired'))
emitter.emit(1 << 31) // fired
Passing less than the default results in some bits beeing ignored:
const emitter = new BitFieldEmitter<void>(31)
emitter.on(1 << 32, () => console.log('fired'))
emitter.emit(1 << 31) // nothing
Calls all handlers which have at least 1 bit in common with the given event code.
const emitter = new BitFieldEmitter<void>()
const handler00 = () => console.log('00')
const handler01 = () => console.log('01')
const handler10 = () => console.log('10')
const handler11 = () => console.log('11')
emitter
.on(0b00, handler00)
.on(0b10, handler10)
.on(0b01, handler01)
.on(0b11, handler11)
emitter
.emit(0b00) // nothing gets called
.emit(0b10) // 10, 11
.emit(0b01) // 01, 11
.emit(0b11) // 01, 10, 11
The code to trigger the listeners with.
The data to pass to the listeners.
The BitFieldEventHandler instance.
Adds an event listener. The listener will be called every time an event which overlaps with the passed code for at least 1 bit is fired.
This methods iterates over all the bits of the event code. When a bit of index n equal to 1 is found, this adds it to the nth set of the handlers property.
const emitter = new BitFieldEmitter<void>()
emitter.on(0b011, () => console.log('fired'))
emitter.emit(0b001) // fired, last bit is the same
emitter.emit(0b100) // nothing, there's no overlap
emitter.emit(0b101) // fired, last bit is the same
emitter.emit(0b110) // fired, second bit is the same
Bitfield containing encoding all the events to listen to.
The function to call when an event fires.
The BitFieldEventHandler instance.
The same as on but calls remove after the first time the event is triggered.
const emitter = new BitFieldEmitter<void>()
const handler = () => console.log('fired')
emitter
.on(1, handler)
.emit(1) // fired
.emit(1) // nothing
The bits to listen for.
The function to call when an event fires.
The BitFieldEventHandler instance.
Removes an event listener from the emitter.
emitter.on(0, handler)
emitter.emit(0, ...) // fires
emitter.remove(handler)
emitter.emit(0,...) // doesn't fire
The event listener to remove.
The BitFieldEventHandler instance.
Takes an iterable and removes the containing handlers from the emitter.
Nothing happens if the iterable contains duplicates but usually it's a good idea to use a set to prevent trying to remove the same element more than once :
const group = new Set([handler1, handler2])
emitter.removeGroup(group)
Set with handlers to remove.
The BitFieldEventHandler instance.
Generated using TypeDoc
The type of data all events will recive. For more details on the topic of type-safety you should read the guide about usage with unions