Function object

Creates a Reactive wrapper with the shape of the input object.

Changing the wrapped object directly does not update the Reactive. Instead, to update values use:

  • set(), 'resets' the whole object
  • update() changes a particular field

Consider using Rx.From.objectProxy to return a object with properties that can be set in the usual way yet is also Reactive.

const o = Rx.From.object({ name: `bob`, level: 2 });
o.onValue(changed => {
});
o.set({ name: `mary`, level: 3 });

// `onValue` will get called, with `changed` having a value of:
// { name: `mary`, level: 3 }

Use last() to get the most recently set value.

onDiff subscribes to a rough diff of the object.

const o = Rx.From.object({ name: `bob`, level: 2 });
o.onDiff(diffValue => {
const diff = diffValue.value;
})
o.set({ name: `mary`, level: 3 });

// onDiff would fire with `diff` of:
[
{ path: `name`, previous: `bob`, value: `mary` },
{ path: `level`, previous: 2, value: 3 }
]

You can also listen to updates on a field via onField.

o.onField(`name`, value => {
// Called whenever the 'name' field is updated
});

Initial value

Options