toosoon-events
v5.0.0
Published
Project providing services implemented as singleton class instances
Downloads
50
Maintainers
Readme
TOOSOON Events
Project providing managers implemented as singleton class instances. They abstract and prevent the process of creating multiple event listeners for common browser events. These managers are particularly useful for managing events that are likely to be listened to by many components.
Installation
Yarn:
$ yarn add toosoon-eventsNPM:
$ npm install toosoon-eventsUsage
import PointerManager, { Pointer } from 'toosoon-events/pointer';
function onPointerStart(pointers: Pointers[]) {
// ...
}
function bind() {
PointerManager.on('start', onPointerStart);
}
function unbind() {
PointerManager.off('start', onPointerStart);
}Managers
KeyboardManager
Utility class for creating keyboard events listeners.
Types
type KeyboardEventKey = 'down' | 'up' | 'press';
type KeyboardListener = (event: KeyboardEvent) => void;PointerManager
Utility class for creating mouse/touch events listeners.
Types
type Pointer = {
x: number;
y: number;
};
type PointerEventKey = 'start' | 'end' | 'move';
type PointerListener = (pointers: Pointer[]) => void;RafManager
Utility class for creating requestAnimationFrame listeners.
Types
type RafListener = (time: number, delta: number) => void;Properties
.time
RafListener.time: numbze;ResizeManager
Utility class for creating resize event listeners.
Types
type ResizeListener = (width: number, height: number) => void;Properties
.width
ResizeManager.width: numbze;.height
ResizeManager.height: numbze;ScrollManager
Utility class for creating scroll event listeners.
Types
type ScrollListener = (event: Event) => void;License
MIT License, see LICENSE for details.

