Handlor
Sir Handlor will assist you with handling events globally across your app and manage in one convenient place. Eliminate code duplication, make maintaining easier.
N.B. This package has TS types and thus is dependent on tslib
.
npm i handlornpm i --save-dev tslib
or
yarn add handloryarn add --dev tslib
Example of usage
; /* Create instance and make it globally */window.handlor = new Handlor;
Interval/Timeout
handlor.registerHandles
RequestAnimationFrame
// interval (same as timeout)handlor.registerHandles
AddEventListener
// interval (same as timeout)handlor.registerHandles
Cleaning events
/** * addEvent returns id of the event which later can be used for clearing a specific item` */window.handlor.cleanItemid; /** * Similarly clean several items at once */ window.handlor.cleanItems; /*** Clean all items.* ⚠️ Careful as this will erase all listeners currently active in the app*/window.handlor.cleanAll;
Checking registered listeners
window.handlor.listeners // { {}, {} }
API
Method | Description | Input |
---|---|---|
registerHandles | List all new or modified files | Single entry or an array of objects |
cleanAll | Removes all listeners from the instance storage | N/A |
cleanItem | Removes a specific item from the storage | id |
cleanItems | Removes an array of specific item from the storage | [id1, id2] |