The information below represents the old API from earlier versions of Object.ts and is kept for historical reference only.
npm install object.tsor
yarn add object.tsimport { 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 aWeakRefor.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 avalueproperty. -
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 thevalueis always aWeakRefand may disappear without notification. -
conditional(cond, ifTrue, ifFalse)Reactive value that switches betweenifTrueandifFalsebased oncond.value. -
safe(target)Prepares an object for serialization to JSON or JSOX.
-
matchMediaRef(mediaValue)Creates a reactiverefbased on amatchMediaquery. -
localStorageRef(name, initial)Creates a persistent reactiverefsynchronized withlocalStorage.- Note: Does not currently react to changes from other tabs or windows with the same key.
| Old API | New API |
|---|---|
makeReactive(obj) |
observe(obj) |
subscribe(obj, cb) |
affected(obj, cb) |
observe(obj, cb) |
iterated(obj, cb) |
deref()- Replaced with utility functionsweak()- No longer availableunified()- Replaced withbindByandderivatematchMediaRef()- Moved to separate librarylocalStorageRef()- Moved to separate library
- BLU.E (2025) — Built on top of Object.ts.
- Uniform.TS — The major sibling project.