Aller au contenu principal

Ref

Index

Accessor

modify

  • modify<Value>(self: Ref<Value>, mapFn: (current: Value) => Value): void
  • Change the current value using a mapping function that returns the new value

    @example
    const ref = Ref('foo');
    Ref.modify(ref, (current) => current + 'bar'); // Ref.read(ref) == 'foobar'

    Type parameters

    • Value

read

  • read<Value>(self: Ref<Value>): Value
  • Returns the current ref value

    @example
    const ref = Ref('foo');
    Ref.read(ref); // 'foo'

    Type parameters

    • Value

write

  • write<Value>(self: Ref<Value>, newValue: Value): void
  • Change the current value

    @example
    const ref = Ref('foo');
    Ref.write(ref, 'bar'); // Ref.read(ref) == 'bar'

    Type parameters

    • Value

Type

hasInstance

  • hasInstance(anyValue: unknown): anyValue is Ref<unknown>
  • Returns true when anyValue has a current property

    @example
    Ref.hasInstance(Ref(123)) // true
    Ref.hasInstance(null)) // false

Other

current

current: current = ...

Current value symbol

property

  • property<T, Name>(self: Ref<T>, propertyName: Name): Ref<T[Name]>
  • @example
    const parent = Ref({ foo: true });
    const child = Ref.property(parent, 'foo');// Ref { current: true }

    Type parameters

    • T: object
    • Name: string | number | symbol