Interface StoreOptions<T>

Store options that can be passed to readable or writable.

interface StoreOptions<T> {
    equal?: ((a, b) => boolean);
    notEqual?: ((a, b) => boolean);
    onUse?: OnUseFn<T>;
}

Type Parameters

  • T

Properties

equal?: ((a, b) => boolean)

Custom function to compare two values, that should return true if they are equal.

It is called when setting a new value to avoid doing anything (such as notifying subscribers) if the value did not change.

Type declaration

    • (a, b): boolean
    • Custom function to compare two values, that should return true if they are equal.

      It is called when setting a new value to avoid doing anything (such as notifying subscribers) if the value did not change.

      Parameters

      • a: T

        First value to compare.

      • b: T

        Second value to compare.

      Returns boolean

      true if a and b are considered equal.

      Remarks

      The default logic (when this option is not present) is to return false if a is a function or an object, or if a and b are different according to Object.is.

      equal takes precedence over notEqual if both are defined.

Remarks

The default logic (when this option is not present) is to return false if a is a function or an object, or if a and b are different according to Object.is.

equal takes precedence over notEqual if both are defined.

Param: a

First value to compare.

Param: b

Second value to compare.

Returns

true if a and b are considered equal.

notEqual?: ((a, b) => boolean)

Custom function to compare two values, that should return true if they are different.

It is called when setting a new value to avoid doing anything (such as notifying subscribers) if the value did not change.

Type declaration

    • (a, b): boolean
    • Custom function to compare two values, that should return true if they are different.

      It is called when setting a new value to avoid doing anything (such as notifying subscribers) if the value did not change.

      Parameters

      • a: T

        First value to compare.

      • b: T

        Second value to compare.

      Returns boolean

      true if a and b are considered different.

      Remarks

      The default logic (when this option is not present) is to return true if a is a function or an object, or if a and b are different according to Object.is.

      StoreOptions.equal takes precedence over notEqual if both are defined.

      Deprecated

      Use StoreOptions.equal instead

Remarks

The default logic (when this option is not present) is to return true if a is a function or an object, or if a and b are different according to Object.is.

StoreOptions.equal takes precedence over notEqual if both are defined.

Deprecated

Use StoreOptions.equal instead

Param: a

First value to compare.

Param: b

Second value to compare.

Returns

true if a and b are considered different.

onUse?: OnUseFn<T>

A function that is called when the number of subscribers changes from 0 to 1 (but not called when the number of subscribers changes from 1 to 2, ...). If it returns a function, that function will be called when the number of subscribers changes from 1 to 0.

Generated using TypeDoc