bndr-js - v0.18.0 / PointerEmitter

Class: PointerEmitter

Hierarchy

  • Emitter<PointerEvent>

    PointerEmitter

Constructors

constructor

new PointerEmitter(target?, options?)

Parameters

NameTypeDefault value
targetPointerEmitterTargetdocument
optionsPick<EmitterOptions<PointerEmitter>, "sources">{}

Overrides

Emitter.constructor

Defined in

src/generator/pointer.ts:85open in new window

Generators

pinch

pinch(options?): Emitter<number>

Creates a generator that emits the pinch delta of the pointer.

Parameters

NameType
options?GeneratorOptions

Returns

Emitter<number>

See

https://kenneth.io/post/detecting-multi-touch-trackpad-gestures-in-javascriptopen in new window

Defined in

src/generator/pointer.ts:576open in new window


scroll

scroll(options?): Emitter<vec2>

Creates a generator that emits the scroll delta of the pointer.

Parameters

NameType
options?GeneratorOptions

Returns

Emitter<vec2>

Defined in

src/generator/pointer.ts:543open in new window

Filters

left

get left(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:468open in new window


middle

get middle(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:475open in new window


mouse

get mouse(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:521open in new window


pen

get pen(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:528open in new window


primary

get primary(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:454open in new window


get right(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:482open in new window


secondary

get secondary(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:461open in new window


touch

get touch(): PointerEmitter

Returns

PointerEmitter

Defined in

src/generator/pointer.ts:535open in new window


down

down(options?): Emitter<true>

Creates an emitter that emits true at the moment the pointer is pressed.

Parameters

NameType
options?GeneratorOptions

Returns

Emitter<true>

Overrides

Emitter.down

Defined in

src/generator/pointer.ts:394open in new window


drag

drag(options?): Emitter<DragData>

Creates a emitter that emits when the pointer is dragged.

Parameters

NameType
options?PointerDragGeneratorOptions

Returns

Emitter<DragData>

Defined in

src/generator/pointer.ts:265open in new window


gestureTransform

gestureTransform(options): Emitter<GestureTransformData>

Parameters

NameType
optionsGeneratorOptions

Returns

Emitter<GestureTransformData>

Defined in

src/generator/pointer.ts:340open in new window


pointerCount

pointerCount(): Emitter<number>

Creates a generator that emits the pointer count.

Returns

Emitter<number>

Defined in

src/generator/pointer.ts:209open in new window


pointerType

pointerType(type, options?): PointerEmitter

Creates a emitter that emits only when the pointer type is the given type.

Parameters

NameTypeDescription
type"mouse" | "pen" | "touch"Pointer type to watch.
options?GeneratorOptions-

Returns

PointerEmitter

A new emitter.

Defined in

src/generator/pointer.ts:499open in new window


position

position(options?): Emitter<vec2>

Creates a generator that emits the position of the pointer.

Parameters

NameType
options?PointerPositionGeneratorOptions

Returns

Emitter<vec2>

Defined in

src/generator/pointer.ts:154open in new window


pressed

pressed(options?): Emitter<boolean>

Creates a generator that emits true when the pointer is pressed.

Parameters

NameType
options?PointerPressedGeneratorOptions

Returns

Emitter<boolean>

Defined in

src/generator/pointer.ts:130open in new window


pressure

pressure(): Emitter<number>

Creates a generator that emits the pressure of the pointer.

Returns

Emitter<number>

Defined in

src/generator/pointer.ts:175open in new window


size

size(): Emitter<vec2>

Creates a generator that emits the size of the pointer.

Returns

Emitter<vec2>

Defined in

src/generator/pointer.ts:200open in new window


tilt

tilt(): Emitter<vec2>

Returns

Emitter<vec2>

Defined in

src/generator/pointer.ts:191open in new window


twist

twist(): Emitter<number>

Returns

Emitter<number>

Defined in

src/generator/pointer.ts:183open in new window


up

up(options?): Emitter<true>

Creates an emitter that emits true at the moment the pointer is released.

Parameters

NameType
options?GeneratorOptions

Returns

Emitter<true>

Overrides

Emitter.up

Defined in

src/generator/pointer.ts:408open in new window


withPointerCount

withPointerCount(count, options?): Emitter<WithPointerCountData>

Creates a generator that emits the list of pointers when the pointer count is the given count.

Parameters

NameType
countnumber
options?GeneratorOptions

Returns

Emitter<WithPointerCountData>

Defined in

src/generator/pointer.ts:230open in new window

Common Filters

change

change(equalFn?): Emitter<PointerEvent>

Emits only when the value is changed

Parameters

NameTypeDefault valueDescription
equalFn(a: PointerEvent, b: PointerEvent) => booleanisEqualA comparator function. The event will be emitted when the function returns falsy value.

Returns

Emitter<PointerEvent>

Inherited from

Emitter.change

Defined in

src/Emitter.ts:305open in new window


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

NameType
valueU

Returns

Emitter<U>

See

https://lodash.com/docs/4.17.15#throttleopen in new window

Inherited from

Emitter.constant

Defined in

src/Emitter.ts:393open in new window


debounce

debounce(wait, options): Emitter<unknown>

Creates debounced version of the current emitter.

Parameters

NameTypeDescription
waitnumberMilliseconds to wait.
optionsDebounceSettings

Returns

Emitter<unknown>

A new emitter

Inherited from

Emitter.debounce

Defined in

src/Emitter.ts:435open in new window


delay

delay(wait): Emitter<unknown>

Creates delayed version of the current emitter.

Parameters

NameTypeDescription
waitnumberMilliseconds to wait.

Returns

Emitter<unknown>

A new emitter

Inherited from

Emitter.delay

Defined in

src/Emitter.ts:460open in new window


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

NameTypeDescription
fn(prev: PointerEvent, curt: PointerEvent) => UA function to calculate the difference

Returns

Emitter<U>

A new emitter

Inherited from

Emitter.delta

Defined in

src/Emitter.ts:679open in new window


filter

filter(fn): Emitter<PointerEvent>

Filters events with the given predicate function

Parameters

NameTypeDescription
fn(value: PointerEvent) => anyReturn truthy value to pass events

Returns

Emitter<PointerEvent>

A new emitter

Inherited from

Emitter.filter

Defined in

src/Emitter.ts:237open in new window


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

NameTypeDescription
fn(value: PointerEvent) => UA function to map the current value. Return undefined to skip emitting.
initialValue?U-

Returns

Emitter<U>

Inherited from

Emitter.filterMap

Defined in

src/Emitter.ts:252open in new window


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

NameTypeDescription
fn(prev: U, value: PointerEvent) => UA function to calculate a new state
initialStateUAn initial state value

Returns

Emitter<U>

A new emitter

Inherited from

Emitter.fold

Defined in

src/Emitter.ts:633open in new window


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

NameTypeDefault valueDescription
msnumber0The interval in milliseconds. Set 0 to use requestAnimationFrame.
immediatebooleanfalseIf set to false, the new emitter waits to emit until the current emitter emits any value.

Returns

Emitter<any>

A new emitter.

Inherited from

Emitter.interval

Defined in

src/Emitter.ts:702open in new window


lerp

lerp(lerp, rate, threshold?): Emitter<PointerEvent>

Smoothen the change rate of the input value.

Parameters

NameTypeDefault valueDescription
lerpLerp<PointerEvent>undefinedA function to interpolate the current value and the target value.
ratenumberundefinedThe ratio of linear interpolation from the current value to the target value with each update.
thresholdnumber1e-4The 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<PointerEvent>

A new emitter

Inherited from

Emitter.lerp

Defined in

src/Emitter.ts:506open in new window


longPress

longPress(wait): Object

Parameters

NameType
waitnumber

Returns

Object

NameType
pressedEmitter<unknown>

Inherited from

Emitter.longPress

Defined in

src/Emitter.ts:476open in new window


map

map<U>(fn, initialValue?): Emitter<U>

Transforms the payload of event with the given function.

Type parameters

Name
U

Parameters

NameTypeDescription
fn(value: PointerEvent) => UA function to transform the payload
initialValue?U-

Returns

Emitter<U>

A new emitter

Inherited from

Emitter.map

Defined in

src/Emitter.ts:224open in new window


not

not(): Emitter<boolean>

Creates an emitter whose payload is negated.

Returns

Emitter<boolean>

Inherited from

Emitter.not

Defined in

src/Emitter.ts:294open in new window


resetBy

resetBy(emitter, emitOnReset?): Emitter<PointerEvent>

Reset the state of current emitter emitter when the given event is fired.

Parameters

NameTypeDefault valueDescription
emitterEmitter<any>undefinedThe emitter that triggers the current emitter to be reset.
emitOnResetbooleantrueIf set to true, the current emitter will be triggered when it is reset.

Returns

Emitter<PointerEvent>

The current emitter emitter

Inherited from

Emitter.resetBy

Defined in

src/Emitter.ts:610open in new window


stash

stash(...triggers): Emitter<any>

Creates an emitter that emits the current value when one of the given events is fired.

Parameters

NameTypeDescription
...triggersEmitter<any>[]Emitters to trigger the current emitter to emit.

Returns

Emitter<any>

A new emitter

Inherited from

Emitter.stash

Defined in

src/Emitter.ts:659open in new window


throttle

throttle(wait, options?): Emitter<PointerEvent>

Creates throttled version of the current emitter.

Parameters

NameTypeDescription
waitnumberMilliseconds to wait.
options?ThrottleSettings

Returns

Emitter<PointerEvent>

See

https://lodash.com/docs/4.17.15#debouncedopen in new window

Inherited from

Emitter.throttle

Defined in

src/Emitter.ts:410open in new window


trail

trail(count?, emitAtCount?): Emitter<PointerEvent[]>

Emits an array caching a specified number of values that were emitted in the past.

Parameters

NameTypeDefault valueDescription
countnumber2The number of cache frames. Set 0 to store caches infinitely.
emitAtCountbooleantrueWhen set to true, events will not be emitted until the count of cache reaches to count.

Returns

Emitter<PointerEvent[]>

Inherited from

Emitter.trail

Defined in

src/Emitter.ts:739open in new window


while

while(emitter, resetOnDown?): Emitter<PointerEvent>

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

NameTypeDefault valueDescription
emitterEmitter<boolean>undefinedAn emitter to filter the events
resetOnDownbooleantrueIf set to true, the returned emitter will be reset when the given emitter is down.

Returns

Emitter<PointerEvent>

Inherited from

Emitter.while

Defined in

src/Emitter.ts:326open in new window

Methods

createDerived

createDerived<U>(options): Emitter<U>

Type parameters

Name
U

Parameters

NameType
optionsEmitterOptions<U> & { propagate: (e: PointerEvent, emit: (v: U) => void) => void }

Returns

Emitter<U>

Inherited from

Emitter.createDerived

Defined in

src/Emitter.ts:80open in new window


registerDerived

registerDerived(emitter, listener): void

Parameters

NameType
emitterEmitter<any>
listenerListener<PointerEvent>

Returns

void

Inherited from

Emitter.registerDerived

Defined in

src/Emitter.ts:72open in new window


tween

tween(lerp, durationMs): Emitter<PointerEvent>

Parameters

NameType
lerpLerp<PointerEvent>
durationMsnumber

Returns

Emitter<PointerEvent>

Inherited from

Emitter.tween

Defined in

src/Emitter.ts:560open in new window

Properties

_disposed

Protected _disposed: boolean = false

Inherited from

Emitter._disposed

Defined in

src/Emitter.ts:61open in new window


derivedEmitters

Protected Readonly derivedEmitters: Map<Emitter<any>, Listener<PointerEvent>>

Stores all deviced events and their listeners. They will not be unregistered by removeAllListeners.

Inherited from

Emitter.derivedEmitters

Defined in

src/Emitter.ts:59open in new window


icon

Optional icon: IconSequence

Inherited from

Emitter.icon

Defined in

src/Emitter.ts:49open in new window


stateful

get stateful(): boolean

Returns true if the emitter has a state and can be reset.

Returns

boolean

Inherited from

Emitter.stateful

Defined in

src/Emitter.ts:137open in new window


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

src/Emitter.ts:162open in new window


button

button(button): PointerEmitter

Creates a emitter that emits only when the given button is pressed.

Parameters

NameTypeDescription
buttonnumber | "left" | "right" | "primary" | "secondary" | "middle"Button to watch.

Returns

PointerEmitter

A new emitter.

Defined in

src/generator/pointer.ts:424open in new window

Accessors

disposed

get disposed(): boolean

Returns

boolean

Inherited from

Emitter.disposed

Defined in

src/Emitter.ts:63open in new window

Commom Filters

split

split(emitter, count, resetOnSwitch?): Emitter<PointerEvent>[]

Splits the current emitter into multiple emitters. Each emitter emits only when the given emitter is changed to the corresponding index.

Parameters

NameTypeDefault valueDescription
emitterEmitter<any>undefinedAn emitter to filter the current event
countnumberundefinedThe number of emitters to be created.
resetOnSwitchbooleantrueIf set to true, the corresponding emitter will be reset when the index of current emitter is switched.

Returns

Emitter<PointerEvent>[]

Inherited from

Emitter.split

Defined in

src/Emitter.ts:355open in new window

Event Handlers

dispose

dispose(): void

Disposes the emitter immediately and prevent to emit any value in the future

Returns

void

Inherited from

Emitter.dispose

Defined in

src/Emitter.ts:119open in new window


emit

emit(value): void

Manually emits the event.

Parameters

NameType
valuePointerEvent

Returns

void

Inherited from

Emitter.emit

Defined in

src/Emitter.ts:190open in new window


log

log(message?): PointerEmitter

Parameters

NameTypeDefault value
messagestring'Bndr'

Returns

PointerEmitter

Inherited from

Emitter.log

Defined in

src/Emitter.ts:757open in new window


off

off(listener): void

Removes the listener function from the event.

Parameters

NameType
listenerListener<PointerEvent>

Returns

void

Inherited from

Emitter.off

Defined in

src/Emitter.ts:181open in new window


on

on(listener): PointerEmitter

Adds the listener function for the event.

Parameters

NameTypeDescription
listenerListener<PointerEvent>The callback function

Returns

PointerEmitter

Inherited from

Emitter.on

Defined in

src/Emitter.ts:171open in new window


once

once(listener): void

Adds a one-time listener function for the event

Parameters

NameType
listenerListener<PointerEvent>

Returns

void

Inherited from

Emitter.once

Defined in

src/Emitter.ts:202open in new window


removeAllListeners

removeAllListeners(): void

Removes all listeners.

Returns

void

Inherited from

Emitter.removeAllListeners

Defined in

src/Emitter.ts:214open in new window


reset

reset(): void

Resets the state of the emitter.

Returns

void

Inherited from

Emitter.reset

Defined in

src/Emitter.ts:145open in new window