unsubs.ts
· 443 B · TypeScript
Brut
/**
* https://github.com/Noah2610/i3-color-theme-editor/blob/master/src/util/unsubs.ts
*/
export interface Unsubs {
add(fn: () => void): void;
unsubAll(): void;
fns: (() => void)[];
}
export function createUnsubs(): Unsubs {
const fns: Unsubs["fns"] = [];
return {
add(fn) {
fns.push(fn);
},
unsubAll() {
fns.forEach((unsub) => unsub());
},
fns,
};
}
| 1 | /** |
| 2 | * https://github.com/Noah2610/i3-color-theme-editor/blob/master/src/util/unsubs.ts |
| 3 | */ |
| 4 | |
| 5 | export interface Unsubs { |
| 6 | add(fn: () => void): void; |
| 7 | unsubAll(): void; |
| 8 | fns: (() => void)[]; |
| 9 | } |
| 10 | |
| 11 | export function createUnsubs(): Unsubs { |
| 12 | const fns: Unsubs["fns"] = []; |
| 13 | |
| 14 | return { |
| 15 | add(fn) { |
| 16 | fns.push(fn); |
| 17 | }, |
| 18 | unsubAll() { |
| 19 | fns.forEach((unsub) => unsub()); |
| 20 | }, |
| 21 | fns, |
| 22 | }; |
| 23 | } |