0.9.3 • Published 8 months ago

json-change-observer-callbacks v0.9.3

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

JsonHookExecutor

JsonHookExecutor is a TypeScript utility class for managing hooks and executing callbacks when changes occur in JSON data with concurrency control. With autocompletion for path.

Installation

Install the package via npm:

npm install json-hook-executor

Usage

import { JsonHookExecutor } from 'json-hook-executor';

// Create an instance of JsonHookExecutor with a concurrency limit (default is 4)
const executor = new JsonHookExecutor();

// Add callback functions to be executed when JSON data changes
executor.addCallback('path.to.data', async () => {
// Your async callback logic here
});

executor.addCallback('another.path', () => {
// Your synchronous callback logic here
});

// Execute all callbacks with concurrency limitation
await executor.executeAll();

// Execute callbacks for changed JSON data with concurrency limitation
await executor.executeForChanges(newData, oldData);

API

constructor(concurrencyLimit: number = 4)

Creates an instance of JsonHookExecutor with an optional concurrency limit.

  • concurrencyLimit (optional): The maximum number of callbacks to run concurrently.

addCallback(path: string, callback: Callback)

Adds a callback function to be executed when JSON data changes at the specified path.

  • path: A string representing the path in the JSON data to watch for changes.
  • callback: The callback function to be executed.

async executeAll()

Executes all added callbacks with the specified concurrency limit.

async executeForChanges(newData: T, oldData?: T)

Executes callbacks for changed JSON data with the specified concurrency limit.

  • newData: The new JSON data.
  • oldData (optional): The old JSON data for comparison.

License

This package is licensed under the ISC License. See the LICENSE file for details.

0.9.3

8 months ago

0.9.2

8 months ago

0.9.1

8 months ago

0.9.0

8 months ago