Returns the current value of this DynamicRef
.
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
is the value to bind to this reference within thunk
's execution
is a parameterless function to execute
the result of executing thunk
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
is the value generator to bind to this reference within thunk
's execution
is a parameterless function to execute
the result of executing thunk
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
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
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
Builds a DynamicRef, where the given parameterless function is going to be the generator for the default value of the returned
Generated using TypeDoc
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 (thethunk
), executes. When that thunk finishes execution, the reference reverts to the previous value.See DynamicRef.bind for a usage sample.