A lightweight TypeScript library for managing hooks.
npm install @typescript-package/hooks --save-peerimport {
// Abstract.
// - Core.
HooksCore,
// - Base.
HooksBase,
ObjectHooksBase,
} from '@typescript-package/hooks';The core abstraction class for hooks functionality.
import { HooksCore } from '@typescript-package/hooks';Base abstraction class for hooks functionality.
import { HooksBase } from '@typescript-package/hooks';The base abstraction class for object hooks functionality.
import { ObjectHooksBase } from '@typescript-package/hooks';
class ReactiveObject<T extends object> extends ObjectHooksBase<T> {
private data: T;
constructor(initial: T, options?: ConstructorParameters<typeof ObjectHooksBase<T>>[0]) {
super(options || {});
this.data = new Proxy(initial, {
set: (target, key, value) => {
if (typeof key === 'string' || typeof key === 'symbol') {
const oldValue = (target as any)[key];
(target as any)[key] = this.triggerOnSetProperty(key as keyof T, value, oldValue);
this.triggerOnPropertyChange(key as keyof T, value, oldValue);
this.triggerOnChange(target as T, this.data);
}
return true;
},
});
}
get value(): T {
return this.data;
}
}
// Usage
const obj = new ReactiveObject({ count: 0 });
obj.onPropertyChange((key, value, oldValue) => {
console.log(`${key} changed from ${oldValue} to ${value}`);
});
obj.value.count = 1; // Triggers onPropertyChange and onChangeYour contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.
Support via:
or via Trust Wallet
Thanks for your support!
By participating in this project, you agree to follow Code of Conduct.
Please follow the following commit message conventions:
The package follows Semantic Versioning 2.0.0 for all releases. The versioning format is:
Given a version number MAJOR.MINOR.PATCH, increment the:
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards-compatible manner, and
- PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
FAQ How should I deal with revisions in the 0.y.z initial development phase?
The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.
How do I know when to release 1.0.0?
If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.
MIT © typescript-package (license)
| Package | Description |
|---|---|
@typedly/callback |
A TypeScript type definitions package for managing hooks. |
@typedly/hooks |
A TypeScript type definitions package for asynchronous and synchronous callback functions of various types. |
- @typescript-package/affix: A lightweight TypeScript library for the affix - prefix and suffix.
- @typescript-package/are: Type-safe
arecheckers for validating value types in TypeScript. - @typescript-package/data: A lightweight TypeScript library for basic data management.
- @typescript-package/descriptor: A lightweight TypeScript library for property descriptor.
- @typescript-package/guard: Type-safe guards for guarding the value types in TypeScript.
- @typescript-package/history: A TypeScript package for tracking history of values.
- @typescript-package/is: Type-safe is checkers for validating value types in TypeScript.
- @typescript-package/name: A lightweight TypeScript library for the name with prefix and suffix.
- @typescript-package/property: A lightweight TypeScript package with features to handle object properties.
- @typescript-package/queue: A lightweight TypeScript library for managing various queue and stack structures.
- @typescript-package/range: A lightweight TypeScript library for managing various types of ranges.
- @typescript-package/regexp: A lightweight TypeScript library for RegExp.
- @typescript-package/state: Simple state management for different types in TypeScript.
- @typescript-package/type: Utility types to enhance and simplify TypeScript development.
- @typescript-package/wrapper: A lightweight TypeScript library to wrap the text with the opening and closing chars.