@edunad/hooks
v1.0.1
Published
LITE Unique Id observables
Downloads
34
Maintainers
Readme
hooks (Typescript)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
LITE Unique Id observables based on garrysmod hooks
Installation
npm install @edunad/hooks
Examples
Local Hooks
class myclass {
public hook: Hook<string> = new Hook<string>();
public hello(): void {
hook.emit('world'); // Transmit "world" to all subscriptions
}
}
class mylistener {
private hookSub: HookSubscription;
public registerHooks(): void {
this.hookSub = myclass.hook.add('my-unique-id', (t: string) = {
console.debug(t); // Will print "world"
});
// or
this.hookSub = myclass.hook.addUnique((t: string) = {
console.debug(t); // Will print "world"
});
}
public unsubHooks(): void {
// Remove subscription
hookSub.destroy(); // or
hook.remove(hookSub); // or
hook.remove('my-unique-id');
}
}
Global Hooks
hooks.add('game-think', 'my-unique-hook', (t: string) = {
console.debug(t); // Will print "world"
});
hooks.add('game-think', 'my-unique-hook-2', (t: string) = {
console.debug(t); // Will print "world"
});
hooks.emit('game-think', 'world');
hooks.remove('game-think', 'my-unique-hook'); // Remove hook