ixfx
    Preparing search index...

    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

    • Type Parameters

      • VextendsRecord<string, any>

      Parameters

      Returns Reactive<V> & { set(value: V): void } & {
          onDiff(changes: (changes: PathDataChange<any>[]) => void): () => void;
          onField(
              fieldName: string,
              handler: (result: ObjectFieldHandler) => void,
          ): () => void;
          update(changedPart: RecursivePartial<V>): V;
          updateField(field: string, value: any): void;
      } & { last(): V }

      • set:function
        • Sets a value

          Parameters

          • value: V

            Value to write

          Returns void

      • onDiff:function
        • Notifies of which field(s) were changed. If you just care about the whole, changed data use the value event.

          Use the returned function to unsubscribe.

          Parameters

          Returns () => void

      • onField:function
        • Notifies when the value of fieldName is changed.

          Use the returned function to unsubscribe.

          Parameters

          Returns () => void

      • update:function
        • Updates the reactive with some partial key-value pairs. Keys omitted are left the same as the current value.

          Parameters

          Returns V

          Returns new value

      • updateField:function
        • Updates a particular field by its path

          Parameters

          • field: string
          • value: any

          Returns void

      • last:function
        • Returns V

    • Type Parameters

      • VextendsRecord<string, any>

      Parameters

      Returns Reactive<V> & { set(value: V): void } & {
          onDiff(changes: (changes: PathDataChange<any>[]) => void): () => void;
          onField(
              fieldName: string,
              handler: (result: ObjectFieldHandler) => void,
          ): () => void;
          update(changedPart: RecursivePartial<V>): V;
          updateField(field: string, value: any): void;
      } & { last(): undefined | V }

      • set:function
        • Sets a value

          Parameters

          • value: V

            Value to write

          Returns void

      • onDiff:function
        • Notifies of which field(s) were changed. If you just care about the whole, changed data use the value event.

          Use the returned function to unsubscribe.

          Parameters

          Returns () => void

      • onField:function
        • Notifies when the value of fieldName is changed.

          Use the returned function to unsubscribe.

          Parameters

          Returns () => void

      • update:function
        • Updates the reactive with some partial key-value pairs. Keys omitted are left the same as the current value.

          Parameters

          Returns V

          Returns new value

      • updateField:function
        • Updates a particular field by its path

          Parameters

          • field: string
          • value: any

          Returns void

      • last:function
        • Returns undefined | V