Reactive utilities and object helpers for JavaScript
Object.ts is a lightweight library providing reactive primitives and object utilities for JavaScript. It is a minor sibling of Uniform.TS
, originally created in early 2024 and partially revisited in 2025. The library is primarily used in internal projects and is designed to be compatible with modern reactive libraries.
- Non-intrusive subscriptions: Subscribers do not retain references to target objects.
- Efficient reactivity: Triggers only on actual value changes.
- Compatibility: Works with recent versions of popular reactive libraries.
npm install object.ts
or
yarn add object.ts
import { makeReactive, ref, subscribe } from 'object.ts';
const state = makeReactive({ count: 0 });
const unsubscribe = subscribe(state, () => {
console.log('State changed:', state.count);
});
state.count = 1; // Triggers subscriber
unsubscribe(); // Unsubscribe when needed
-
makeReactive(initial)
Creates a reactive primitive from an existing object. -
subscribe(obj, [key], callback)
Subscribes to changes in an observable object,Set
, orMap
.- Supports
[obj, key]
to subscribe to a specific property. - Returns an unsubscribe function.
- Supports
-
deref(obj)
Dereferences aWeakRef
or.value
-based object. -
promised(obj)
Wraps an awaitable promise as a reactive value.- Reacts only to
Promise.resolve
.
- Reacts only to
-
ref(initial)
Creates an observable reference with avalue
property. -
computed(sub)
Similar toref
, but computes its value from a reactive source.- Setting the value has no effect on the source.
-
unified(...objs)
Combines multiple observable objects into one (read-only). -
remap(obj, cb)
Creates a remapped reactive object with a different keyset (read-only). -
weak(initial)
Likeref
, but thevalue
is always aWeakRef
and may disappear without notification. -
conditional(cond, ifTrue, ifFalse)
Reactive value that switches betweenifTrue
andifFalse
based oncond.value
. -
safe(target)
Prepares an object for serialization to JSON or JSOX.
-
matchMediaRef(mediaValue)
Creates a reactiveref
based on amatchMedia
query. -
localStorageRef(name, initial)
Creates a persistent reactiveref
synchronized withlocalStorage
.- Note: Does not currently react to changes from other tabs or windows with the same key.
- BLU.E (2025) — Built on top of Object.ts.
- Uniform.TS — The major sibling project.
This project is licensed under the MIT License.
For more information, see the GitHub repository.