Function changeWith

  • Convenient for mutation of cells that contian non-primitive values (e.g. arrays, or objects). Specifies that the cell value should be changed when source emits, with the result of the map callback parameter. the map parameter gets called with the current value of the cell and the value published through the source.

    Type Parameters

    • T

      the type of the cell value.

    • K

      the type of the value published through the source.

    Parameters

    Returns void

    const items$ = Cell<string[]([])
    const addItem$ = Signal<string>(false, (r) => {
    r.changeWith(items$, addItem$, (items, item) => [...items, item])
    })
    const r = new Realm()
    r.pub(addItem$, 'foo')
    r.pub(addItem$, 'bar')
    r.getValue(items$) // ['foo', 'bar']