bndr-js - v0.18.6 / KeyboardEmitter
Class: KeyboardEmitter
Hierarchy
Emitter<KeyboardEmitterEvent>↳
KeyboardEmitter
Constructors
constructor
• new KeyboardEmitter(target?)
Parameters
| Name | Type | Default value |
|---|---|---|
target | string | Window | HTMLElement | window |
Overrides
Defined in
Generators
hotkey
▸ hotkey(hotkey, options?): Emitter<true>
Parameters
| Name | Type |
|---|---|
hotkey | string |
options? | HotkeyOptions |
Returns
Emitter<true>
Defined in
keydown
▸ keydown(key, options?): Emitter<true>
Parameters
| Name | Type |
|---|---|
key | string |
options? | KeyboardGeneratorOptions |
Returns
Emitter<true>
Defined in
keyup
▸ keyup(key, options?): Emitter<true>
Parameters
| Name | Type |
|---|---|
key | string |
options? | KeyboardGeneratorOptions |
Returns
Emitter<true>
Defined in
pressed
▸ pressed(key, options?): Emitter<boolean>
Parameters
| Name | Type |
|---|---|
key | string |
options? | KeyboardGeneratorOptions |
Returns
Emitter<boolean>
Defined in
Common Filters
change
▸ change(equalFn?): Emitter<KeyboardEmitterEvent>
Emits only when the value is changed
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
equalFn | (a: KeyboardEmitterEvent, b: KeyboardEmitterEvent) => boolean | isEqual | A comparator function. The event will be emitted when the function returns falsy value. |
Returns
Emitter<KeyboardEmitterEvent>
Inherited from
Defined in
constant
▸ constant<U>(value): Emitter<U>
Creates an emitter that emits a constant value every time the current emitter is emitted.
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type |
|---|---|
value | U |
Returns
Emitter<U>
See
https://lodash.com/docs/4.17.15#throttle
Inherited from
Defined in
debounce
▸ debounce(wait, options): Emitter<unknown>
Creates debounced version of the current emitter.
Parameters
| Name | Type | Description |
|---|---|---|
wait | number | Milliseconds to wait. |
options | DebounceSettings |
Returns
Emitter<unknown>
A new emitter
Inherited from
Defined in
delay
▸ delay(wait): Emitter<unknown>
Creates delayed version of the current emitter.
Parameters
| Name | Type | Description |
|---|---|---|
wait | number | Milliseconds to wait. |
Returns
Emitter<unknown>
A new emitter
Inherited from
Defined in
delta
▸ delta<U>(fn): Emitter<U>
Creates an emitter that emits the ‘difference’ between the current value and the previous value.
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type | Description |
|---|---|---|
fn | (prev: KeyboardEmitterEvent, curt: KeyboardEmitterEvent) => U | A function to calculate the difference |
Returns
Emitter<U>
A new emitter
Inherited from
Defined in
down
▸ down(): Emitter<true>
Creates an emitter that emits at the moment the current value changes from falsy to truthy.
Returns
Emitter<true>
Inherited from
Defined in
filter
▸ filter(fn): Emitter<KeyboardEmitterEvent>
Filters events with the given predicate function
Parameters
| Name | Type | Description |
|---|---|---|
fn | (value: KeyboardEmitterEvent) => any | Return truthy value to pass events |
Returns
Emitter<KeyboardEmitterEvent>
A new emitter
Inherited from
Defined in
filterMap
▸ filterMap<U>(fn, initialValue?): Emitter<U>
Maps the current value to another type of value, and emits the mapped value only when the mapped value is not undefined.
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type | Description |
|---|---|---|
fn | (value: KeyboardEmitterEvent) => U | A function to map the current value. Return undefined to skip emitting. |
initialValue? | U | - |
Returns
Emitter<U>
Inherited from
Defined in
fold
▸ fold<U>(fn, initialState): Emitter<U>
Initializes with an initialState value. On each emitted event, calculates a new state based on the previous state and the current value, and emits this new state.
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type | Description |
|---|---|---|
fn | (prev: U, value: KeyboardEmitterEvent) => U | A function to calculate a new state |
initialState | U | An initial state value |
Returns
Emitter<U>
A new emitter
Inherited from
Defined in
interval
▸ interval(ms?, immediate?): Emitter<any>
Creates an emitter that keeps to emit the last value of the current emitter at the specified interval.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
ms | number | 0 | The interval in milliseconds. Set 0 to use requestAnimationFrame. |
immediate | boolean | false | If set to false, the new emitter waits to emit until the current emitter emits any value. |
Returns
Emitter<any>
A new emitter.
Inherited from
Defined in
lerp
▸ lerp(lerp, rate, threshold?): Emitter<KeyboardEmitterEvent>
Smoothen the change rate of the input value.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
lerp | Lerp<KeyboardEmitterEvent> | undefined | A function to interpolate the current value and the target value. |
rate | number | undefined | The ratio of linear interpolation from the current value to the target value with each update. |
threshold | number | 1e-4 | The threshold to determine whether the current value is close enough to the target value. If the difference between the current value and the target value is less than this value, the target value will be used as the current value and the interpolation will be stopped. |
Returns
Emitter<KeyboardEmitterEvent>
A new emitter
Inherited from
Defined in
longPress
▸ longPress(wait): Object
Parameters
| Name | Type |
|---|---|
wait | number |
Returns
Object
| Name | Type |
|---|---|
pressed | Emitter<unknown> |
Inherited from
Defined in
map
▸ map<U>(fn, initialValue?): Emitter<U>
Transforms the payload of event with the given function.
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type | Description |
|---|---|---|
fn | (value: KeyboardEmitterEvent) => U | A function to transform the payload |
initialValue? | U | - |
Returns
Emitter<U>
A new emitter
Inherited from
Defined in
not
▸ not(): Emitter<boolean>
Creates an emitter whose payload is negated.
Returns
Emitter<boolean>
Inherited from
Defined in
resetBy
▸ resetBy(emitter, emitOnReset?): Emitter<KeyboardEmitterEvent>
Reset the state of current emitter emitter when the given event is fired.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
emitter | Emitter<any> | undefined | The emitter that triggers the current emitter to be reset. |
emitOnReset | boolean | true | If set to true, the current emitter will be triggered when it is reset. |
Returns
Emitter<KeyboardEmitterEvent>
The current emitter emitter
Inherited from
Defined in
stash
▸ stash(...triggers): Emitter<any>
Creates an emitter that emits the current value when one of the given events is fired.
Parameters
| Name | Type | Description |
|---|---|---|
...triggers | Emitter<any>[] | Emitters to trigger the current emitter to emit. |
Returns
Emitter<any>
A new emitter
Inherited from
Defined in
throttle
▸ throttle(wait, options?): Emitter<KeyboardEmitterEvent>
Creates throttled version of the current emitter.
Parameters
| Name | Type | Description |
|---|---|---|
wait | number | Milliseconds to wait. |
options? | ThrottleSettings |
Returns
Emitter<KeyboardEmitterEvent>
See
https://lodash.com/docs/4.17.15#debounced
Inherited from
Defined in
trail
▸ trail(count?, emitAtCount?): Emitter<KeyboardEmitterEvent[]>
Emits an array caching a specified number of values that were emitted in the past.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
count | number | 2 | The number of cache frames. Set 0 to store caches infinitely. |
emitAtCount | boolean | true | When set to true, events will not be emitted until the count of cache reaches to count. |
Returns
Emitter<KeyboardEmitterEvent[]>
Inherited from
Defined in
up
▸ up(): Emitter<true>
Creates an emitter that emits at the moment the current value changes from falsy to truthy.
Returns
Emitter<true>
Inherited from
Defined in
while
▸ while(emitter, resetOnDown?): Emitter<KeyboardEmitterEvent>
Emits while the given event is truthy. The event will be also emitted when the given emitter is changed from falsy to truthy when the resetOnDown flag is set to true.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
emitter | Emitter<boolean> | undefined | An emitter to filter the events |
resetOnDown | boolean | true | If set to true, the returned emitter will be reset when the given emitter is down. |
Returns
Emitter<KeyboardEmitterEvent>
Inherited from
Defined in
Methods
createDerived
▸ createDerived<U>(options): Emitter<U>
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type |
|---|---|
options | EmitterOptions<U> & { propagate: (e: KeyboardEmitterEvent, emit: (v: U) => void) => void } |
Returns
Emitter<U>
Inherited from
Defined in
registerDerived
▸ registerDerived(emitter, listener): void
Parameters
| Name | Type |
|---|---|
emitter | Emitter<any> |
listener | Listener<KeyboardEmitterEvent> |
Returns
void
Inherited from
Defined in
tween
▸ tween(lerp, durationMs): Emitter<KeyboardEmitterEvent>
Parameters
| Name | Type |
|---|---|
lerp | Lerp<KeyboardEmitterEvent> |
durationMs | number |
Returns
Emitter<KeyboardEmitterEvent>
Inherited from
Defined in
Properties
_disposed
• Protected _disposed: boolean = false
Inherited from
Defined in
derivedEmitters
• Protected Readonly derivedEmitters: Map<Emitter<any>, Listener<KeyboardEmitterEvent>>
Stores all deviced events and their listeners. They will not be unregistered by removeAllListeners.
Inherited from
Defined in
icon
• Optional icon: IconSequence
Inherited from
Defined in
stateful
• get stateful(): boolean
Returns true if the emitter has a state and can be reset.
Returns
boolean
Inherited from
Emitter.stateful
Defined in
value
• get value(): T
The latest value emitted from the emitter. If the emitter has never fired before, it just returns undefined.
Returns
T
Inherited from
Emitter.value
Defined in
Accessors
disposed
• get disposed(): boolean
Returns
boolean
Inherited from
Emitter.disposed
Defined in
Commom Filters
split
▸ split(emitter, count, resetOnSwitch?): Emitter<KeyboardEmitterEvent>[]
Splits the current emitter into multiple emitters. Each emitter emits only when the given emitter is changed to the corresponding index.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
emitter | Emitter<any> | undefined | An emitter to filter the current event |
count | number | undefined | The number of emitters to be created. |
resetOnSwitch | boolean | true | If set to true, the corresponding emitter will be reset when the index of current emitter is switched. |
Returns
Emitter<KeyboardEmitterEvent>[]
Inherited from
Defined in
Event Handlers
dispose
▸ dispose(): void
Disposes the emitter immediately and prevent to emit any value in the future
Returns
void
Inherited from
Defined in
emit
▸ emit(value): void
Manually emits the event.
Parameters
| Name | Type |
|---|---|
value | KeyboardEmitterEvent |
Returns
void
Inherited from
Defined in
log
▸ log(message?): KeyboardEmitter
Parameters
| Name | Type | Default value |
|---|---|---|
message | string | 'Bndr' |
Returns
Inherited from
Defined in
off
▸ off(listener): void
Removes the listener function from the event.
Parameters
| Name | Type |
|---|---|
listener | Listener<KeyboardEmitterEvent> |
Returns
void
Inherited from
Defined in
on
▸ on(listener): KeyboardEmitter
Adds the listener function for the event.
Parameters
| Name | Type | Description |
|---|---|---|
listener | Listener<KeyboardEmitterEvent> | The callback function |
Returns
Inherited from
Defined in
once
▸ once(listener): void
Adds a one-time listener function for the event
Parameters
| Name | Type |
|---|---|
listener | Listener<KeyboardEmitterEvent> |
Returns
void
Inherited from
Defined in
removeAllListeners
▸ removeAllListeners(): void
Removes all listeners.
Returns
void
Inherited from
Defined in
reset
▸ reset(): void
Resets the state of the emitter.
Returns
void