ComputedStateInstance
A computed state is a state that is derived from other states
.id
The internal id of the computed state
.instanceId
The internal id of the computed state with an instance prefix
.value
The value (reactive) of the state
.lastValue
The previous value of the state
.name
The name of the state (NOTE: set with the .key()
function)
.deps
Returns a list of dependencies for the computed state
.refreshDeps()
Internal Helper Function; for each dependency, add a watcher to the state that will update the computed state when a dependency changes
Internal:
.watch(callback) ⇒
Watch for changes on this computed state
Returns:
The remove function to stop watching
Param | Description |
---|---|
callback | The callback to run when the state changes |
.set(value)
Internal: This would normally be passed from WatchableValue, but Watchable value has a set function that is public. We are not allowing the user to set the value of the state explicitly, so we recreate this function and make it private
Param | Description |
---|---|
value | The value to set the state to |
.addDep(dep)
Adds a dependency to the computed state
Param |
---|
dep |
.removeDep(dep)
Removes a dependency from the computed state
Param |
---|
dep |
.undo()
Reset the state to the previous value
.reset()
Reset the state to the initial value
.key()
Set the key of the state for enhanced internal tracking
.recompute()
Recompute the value of the computed state