Function sub

  • Subscribes to the values published in the referred node.

    Type Parameters

    • T

    Parameters

    • node: NodeRef<T>

      the cell/signal to subscribe to.

    • subscription: Subscription<T>

      the callback to execute when the node receives a new value.

    Returns UnsubscribeHandle

    a function that, when called, will cancel the subscription.

    const signal$ = Signal<number>()
    const r = new Realm()
    const unsub = r.sub(signal$, console.log)
    r.pub(signal$, 2)
    unsub()
    r.pub(signal$, 3)