Uneventful
    • Keep an expression's old value unless there's a semantic change

      By default, reactive values (i.e. cached(), or value() with a setf()) are considered to have "changed" (and thus trigger recalculation of their dependents) when they are different according to === comparison.

      This works well for primitive values, but for arrays and objects it's not always ideal, because two arrays can have the exact same elements and still be different according to ===. So this function lets you substitute a different comparison function (like a deep-equal or shallow-equal) instead.

      Specifically, if your reactive expression returns stable(compare, newVal), then the expression's previous value will be kept if the compare function returns true when called with the old and new values. Otherwise, the new value will be used.

      Type Parameters

      • T

      Parameters

      • equals: (v1: T, v2: T) => boolean
      • newVal: T

      Returns T

      • If the reactive expression's last "value" was an error, the new value is returned.
      • An error will be thrown if this function is called outside a reactive expression or from within a peek() call or action wrapper.
      • You can use the stabilizer() function to create custom functions similar to stableJSON. or stableArray().
    MMNEPVFCICPMFPCPTTAAATR