bndr-js - v0.18.0 / PointerEmitter
Class: PointerEmitter
Hierarchy
Emitter
<PointerEvent
>↳
PointerEmitter
Constructors
constructor
• new PointerEmitter(target?
, options?
)
Parameters
Name | Type | Default value |
---|---|---|
target | PointerEmitterTarget | document |
options | Pick <EmitterOptions <PointerEmitter >, "sources" > | {} |
Overrides
Defined in
Generators
pinch
▸ pinch(options?
): Emitter
<number
>
Creates a generator that emits the pinch delta of the pointer.
Parameters
Name | Type |
---|---|
options? | GeneratorOptions |
Returns
Emitter
<number
>
See
https://kenneth.io/post/detecting-multi-touch-trackpad-gestures-in-javascript
Defined in
scroll
▸ scroll(options?
): Emitter
<vec2
>
Creates a generator that emits the scroll delta of the pointer.
Parameters
Name | Type |
---|---|
options? | GeneratorOptions |
Returns
Emitter
<vec2
>
Defined in
Filters
left
• get
left(): PointerEmitter
Returns
Defined in
middle
• get
middle(): PointerEmitter
Returns
Defined in
mouse
• get
mouse(): PointerEmitter
Returns
Defined in
pen
• get
pen(): PointerEmitter
Returns
Defined in
primary
• get
primary(): PointerEmitter
Returns
Defined in
right
• get
right(): PointerEmitter
Returns
Defined in
secondary
• get
secondary(): PointerEmitter
Returns
Defined in
touch
• get
touch(): PointerEmitter
Returns
Defined in
down
▸ down(options?
): Emitter
<true
>
Creates an emitter that emits true
at the moment the pointer is pressed.
Parameters
Name | Type |
---|---|
options? | GeneratorOptions |
Returns
Emitter
<true
>
Overrides
Defined in
drag
▸ drag(options?
): Emitter
<DragData
>
Creates a emitter that emits when the pointer is dragged.
Parameters
Name | Type |
---|---|
options? | PointerDragGeneratorOptions |
Returns
Defined in
gestureTransform
▸ gestureTransform(options
): Emitter
<GestureTransformData
>
Parameters
Name | Type |
---|---|
options | GeneratorOptions |
Returns
Emitter
<GestureTransformData
>
Defined in
pointerCount
▸ pointerCount(): Emitter
<number
>
Creates a generator that emits the pointer count.
Returns
Emitter
<number
>
Defined in
pointerType
▸ pointerType(type
, options?
): PointerEmitter
Creates a emitter that emits only when the pointer type is the given type.
Parameters
Name | Type | Description |
---|---|---|
type | "mouse" | "pen" | "touch" | Pointer type to watch. |
options? | GeneratorOptions | - |
Returns
A new emitter.
Defined in
position
▸ position(options?
): Emitter
<vec2
>
Creates a generator that emits the position of the pointer.
Parameters
Name | Type |
---|---|
options? | PointerPositionGeneratorOptions |
Returns
Emitter
<vec2
>
Defined in
pressed
▸ pressed(options?
): Emitter
<boolean
>
Creates a generator that emits true
when the pointer is pressed.
Parameters
Name | Type |
---|---|
options? | PointerPressedGeneratorOptions |
Returns
Emitter
<boolean
>
Defined in
pressure
▸ pressure(): Emitter
<number
>
Creates a generator that emits the pressure of the pointer.
Returns
Emitter
<number
>
Defined in
size
▸ size(): Emitter
<vec2
>
Creates a generator that emits the size of the pointer.
Returns
Emitter
<vec2
>
Defined in
tilt
▸ tilt(): Emitter
<vec2
>
Returns
Emitter
<vec2
>
Defined in
twist
▸ twist(): Emitter
<number
>
Returns
Emitter
<number
>
Defined in
up
▸ up(options?
): Emitter
<true
>
Creates an emitter that emits true
at the moment the pointer is released.
Parameters
Name | Type |
---|---|
options? | GeneratorOptions |
Returns
Emitter
<true
>
Overrides
Defined in
withPointerCount
▸ withPointerCount(count
, options?
): Emitter
<WithPointerCountData
>
Creates a generator that emits the list of pointers when the pointer count is the given count.
Parameters
Name | Type |
---|---|
count | number |
options? | GeneratorOptions |
Returns
Emitter
<WithPointerCountData
>
Defined in
Common Filters
change
▸ change(equalFn?
): Emitter
<PointerEvent
>
Emits only when the value is changed
Parameters
Name | Type | Default value | Description |
---|---|---|---|
equalFn | (a : PointerEvent , b : PointerEvent ) => boolean | isEqual | A comparator function. The event will be emitted when the function returns falsy value. |
Returns
Emitter
<PointerEvent
>
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 : PointerEvent , curt : PointerEvent ) => U | A function to calculate the difference |
Returns
Emitter
<U
>
A new emitter
Inherited from
Defined in
filter
▸ filter(fn
): Emitter
<PointerEvent
>
Filters events with the given predicate function
Parameters
Name | Type | Description |
---|---|---|
fn | (value : PointerEvent ) => any | Return truthy value to pass events |
Returns
Emitter
<PointerEvent
>
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 : PointerEvent ) => 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 : PointerEvent ) => 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
<PointerEvent
>
Smoothen the change rate of the input value.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
lerp | Lerp <PointerEvent > | 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
<PointerEvent
>
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 : PointerEvent ) => 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
<PointerEvent
>
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
<PointerEvent
>
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
<PointerEvent
>
Creates throttled version of the current emitter.
Parameters
Name | Type | Description |
---|---|---|
wait | number | Milliseconds to wait. |
options? | ThrottleSettings |
Returns
Emitter
<PointerEvent
>
See
https://lodash.com/docs/4.17.15#debounced
Inherited from
Defined in
trail
▸ trail(count?
, emitAtCount?
): Emitter
<PointerEvent
[]>
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
<PointerEvent
[]>
Inherited from
Defined in
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
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
<PointerEvent
>
Inherited from
Defined in
Methods
createDerived
▸ createDerived<U
>(options
): Emitter
<U
>
Type parameters
Name |
---|
U |
Parameters
Name | Type |
---|---|
options | EmitterOptions <U > & { propagate : (e : PointerEvent , 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 <PointerEvent > |
Returns
void
Inherited from
Defined in
tween
▸ tween(lerp
, durationMs
): Emitter
<PointerEvent
>
Parameters
Name | Type |
---|---|
lerp | Lerp <PointerEvent > |
durationMs | number |
Returns
Emitter
<PointerEvent
>
Inherited from
Defined in
Properties
_disposed
• Protected
_disposed: boolean
= false
Inherited from
Defined in
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
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
button
▸ button(button
): PointerEmitter
Creates a emitter that emits only when the given button is pressed.
Parameters
Name | Type | Description |
---|---|---|
button | number | "left" | "right" | "primary" | "secondary" | "middle" | Button to watch. |
Returns
A new emitter.
Defined in
Accessors
disposed
• get
disposed(): boolean
Returns
boolean
Inherited from
Emitter.disposed
Defined in
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
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
<PointerEvent
>[]
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 | PointerEvent |
Returns
void
Inherited from
Defined in
log
▸ log(message?
): PointerEmitter
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 <PointerEvent > |
Returns
void
Inherited from
Defined in
on
▸ on(listener
): PointerEmitter
Adds the listener
function for the event.
Parameters
Name | Type | Description |
---|---|---|
listener | Listener <PointerEvent > | 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 <PointerEvent > |
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