Options
All
  • Public
  • Public/Protected
  • All
Menu

DynamicRef provides a binding mechanism where the current value is found through dynamic scope, but where access to the variable itself is resolved through static scope.

The current value can be retrieved with the DynamicRef.get method. New values should be pushed using the DynamicRef.bind method.

Values pushed via bind only stay valid while its second argument, a parameterless function (the thunk), executes. When that thunk finishes execution, the reference reverts to the previous value.

See DynamicRef.bind for a usage sample.

final

Type parameters

  • A

Hierarchy

  • DynamicRef

Index

Properties

Methods

Properties

get

get: function

Returns the current value of this DynamicRef.

Type declaration

    • (): A
    • Returns A

Methods

bind

  • bind<R>(value: A, thunk: function): R
  • Binds this DynamicRef to a different (strict) value that's going to be visible while executing thunk and then it will get reverted to its previous value.

    Sample:

    const ref = DynamicRef.of(() => "original")
    
    ref.get() // original
    
    ref.bind("modified", () => {
      ref.get() // modified
    })
    
    ref.get() // original
    
    see

    bindL for binding a non-strict value instead.

    Type parameters

    • R

    Parameters

    • value: A

      is the value to bind to this reference within thunk's execution

    • thunk: function

      is a parameterless function to execute

        • (): R
        • Returns R

    Returns R

    the result of executing thunk

bindL

  • bindL<R>(value: function, thunk: function): R
  • Binds this DynamicRef to a different (non-strict) value that's going to be visible while executing thunk and then it will get reverted to its previous value.

    Sample:

    const ref = DynamicRef.of(() => "original")
    
    ref.get() // original
    
    ref.bindL(() => "modified", () => {
      ref.get() // modified
    })
    
    ref.get() // original
    
    see

    bind for binding a strict value instead.

    Type parameters

    • R

    Parameters

    • value: function

      is the value generator to bind to this reference within thunk's execution

        • (): A
        • Returns A

    • thunk: function

      is a parameterless function to execute

        • (): R
        • Returns R

    Returns R

    the result of executing thunk

revert

  • revert(): void
  • Reverts this DynamicRef to a previous state, if a previous state is available due to calling set or setL.

    const ref = DynamicRef.of(() => "initial")
    
    ref.set("state 2")
    ref.set("state 3")
    ref.get() // Yields: state 3
    
    ref.revert()
    ref.get() // Yields: state 2
    
    ref.revert()
    ref.get() // Yields: initial
    
    ref.revert() // No-op
    ref.get() // Yields: initial
    

    Returns void

set

  • set(value: A): void
  • Updates the underlying of this DynamicRef to the given value.

    Note that the previous state can be reverted with revert:

    const ref = DynamicRef.of(() => "initial")
    
    ref.set("another")
    ref.get() // another
    
    ref.revert()
    ref.get() // initial
    

    Parameters

    • value: A

    Returns void

setL

  • setL(thunk: function): void
  • Updates the underlying of this DynamicRef to values generated by the given thunk.

    Note that the previous state can be reverted with revert:

    const ref = DynamicRef.of(() => "initial")
    
    ref.setL(() => "another")
    ref.get() // another
    
    ref.revert()
    ref.get() // initial
    

    Parameters

    • thunk: function
        • (): A
        • Returns A

    Returns void

Static of

  • Builds a DynamicRef, where the given parameterless function is going to be the generator for the default value of the returned

    Type parameters

    • A

    Parameters

    • fn: function
        • (): A
        • Returns A

    Returns DynamicRef<A>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc