unsubscriber

npm version bundle size

How to easy collect unsubscribe functions for several sources.

import { unsubscriber, collect, attach, run, scope } from "unsubscriber";

const unsubs = unsubscriber();

// Run code and collect unsubscribers
const app = collect(usubs, () => {
  attach(() => {
    console.log('unsubscribe');
  });

  attach(scope(), () => {});
  return new App();
});

const detach = attach(usubs, () => {});

run(usubs);

Context dependent functions who available into the function body:

const app = collect(usubs, () => {

  const detach = attach(unsubscriber);

});

Enjoy your code!

GitHub

View Github