Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@tinkoff/hook-runner

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinkoff/hook-runner

Library used for subscription on specific events in different styles: sync, async, promise.

latest
Source
npmnpm
Version
0.7.5
Version published
Maintainers
0
Created
Source

Hooks

Library used for subscription on specific events in different styles: sync, async, promise.

Explanation

Working with lib consist of two phases:

  • Adding in the target code hook runner call, e.g. runAsyncHooks, with unique event key and additional parameters. It creates a slot for this event that allow to subscribe on the event.
  • Registering hook handler with registerHooks that will be executed when run... function will be called

Caveats

There is different types hooks that are not interoperable. So carefully add new registrations with checking expected hook type.

Also you should preserve data chain, e.g. return data with same interface from hook, as it otherwise may break other hooks.

API

Hooks

Create new instance of @tinkoff/hook-runner

import { Hooks } from '@tinkoff/hook-runner';

const hookRunner = new Hooks();

registerHooks(key, hooks)

Register new hook for a specific key.

runHooks(key, context, payload, options)

Execute sync hooks. payload is passed through every hook and will be returned as a result (it may be changed by hooks).

runAsyncHooks(key, context, payload, options)

Executes async hooks using setTimeout. payload is passed to every hook with its initial value.

runPromiseHooks(key, context, options) => (payload) => Promise

Execute promise-based hooks. payload is passed through every hook and will be returned as a result (it may be changed by hooks)

Hooks

Types

sync

Accepts (context, payload, options). Hooks are running in order passing previous hook result as input for next hook.

async

Accepts (context, payload, options). Hooks are running independently from each other.

promise

Accepts (context, payload, options). Hooks are running in order passing previous hook result as input for next hook with wrapping call in promise.

FAQs

Package last updated on 23 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts