Utility class for cleaning up various destructible things like timeouts, disposable items and whatever you want to add.
yarn add seng-disposable-manager
npm i -S seng-disposable-manager
// Construct
const instance = new DisposableManager();
// Disposable item
const fooBar = {
dispose: () => {}
};
// Add disposable item
instance.add(fooBar);
// Add interval
instance.add(
setInterval(() => {
foo();
}, 500),
DisposableTypes.INTERVAL,
);
// Or Add interval via addInterval method
instance.addInterval(
setInterval(() => {
foo();
}, 500)
);
in the callback you will get the item that you have added via the 'add' method which you can destroy/cleanup.
DisposableManager.register('destruct', ((instance) => {
instance.destruct();
));
const foo = {
destruct: () => {}
}
disposableManagerInstance.add(foo, 'destruct');
This will clean up all the added instances, timeouts and custom added items/types.
disposableManagerInstance.dispose();
In order to build seng-disposable-manager, ensure that you have Git and [Node.js] (http://nodejs .org/) installed.
Clone a copy of the repo:
git clone https://github.com/riccomediamonks/seng-disposable-manager.git
Change to the seng-disposable-manager directory:
cd seng-disposable-manager
Install dev dependencies:
yarn
Use one of the following main scripts:
yarn build # build this project
yarn dev # run dev-watch mode, serving example/index.html in the browser
yarn generate # generate all artifacts (compiles ts, webpack, docs and coverage)
yarn test:unit # run the unit tests
yarn validate # runs validation scripts, including test, lint and coverage check
yarn lint # run tslint on this project
yarn doc # generate typedoc documentation
When installing this module, it adds a pre-push hook, that runs the validate
script before committing, so you can be sure that everything checks out.