Function: makeReactive
index.makeReactive
makeReactive<T>(target): T
Wraps a target object, class instance, Array, Set, or Map in a deep fine-grained reactive Proxy.
Type parameters
| Name |
Description |
T |
The type of target object or collection to make reactive. |
Parameters
| Name |
Type |
Description |
target |
T |
The object, class instance, array, Set, or Map to wrap. |
Returns
T
A reactive Proxy wrapping the target, or the original value if primitive or non-trappable.
Remarks
makeReactive is the foundational proxy transformer in the signals system.
- Property Traps: Intercepts
get, set, deleteProperty, has, and ownKeys to record fine-grained dependency edges and schedule invalidation reactions.
- Constructor Self-Reactivity: Can be returned directly inside class constructors (e.g. Domain Aggregate Roots or Entity classes) via
return makeReactive(this);.
- Method Batching: Member methods invoked on a reactive proxy are automatically wrapped in a batch transaction to prevent redundant intermediate reactions.
- Deep Reactivity: Reading nested objects, arrays, Sets, or Maps lazily wraps them in reactive proxies.
- Identity & Idempotency: Repeated calls on the same target return the same cached proxy instance.
- Non-Trappable Objects: Instances of
Date, RegExp, Promise, Error, WeakMap, and WeakSet are preserved without proxy wrapping.
Example
import { makeReactive, effect } from '@banksia/signals';
// 1. Plain Object
const user = makeReactive({ name: 'Alice', age: 30 });
effect(() => console.log(`${user.name} is ${user.age} years old`));
user.age = 31; // Triggers reaction
// 2. Class Constructor Self-Reactivity
class CounterStore {
public count = 0;
constructor() {
return makeReactive(this);
}
public increment() {
this.count++;
}
}
const counter = new CounterStore();