Skip to navigation

ReadonlyWatchable (interface)

Web SDK v5 API reference
View as Markdown

Watchable

Basic WebSDK reactive type for immutable structures and primitives, the same as Watchable, but with readonly values. Setting a new value is ignored without any error, with only a warn message in the console.

Methods

Properties

Methods

clear

clear(): void

Clears all observers for this watchable excluding the ones created with WatchOptions.clearable: false.

Returns: void

reset

reset(value?: T): void

Sets both Watchable.value and Watchable.oldValue to the given or initial value.

The Watchable.watch callback is triggered only when the reset value differs from the current Watchable.value. It receives the previous content as its second argument, but Watchable.oldValue is already reset.

Does not remove watchers.

Note: Teardown is a common use case, since assigning null is not enough - the watchable holds a reference to the previous value.

Since: 5.4.0

Parameters

ParameterTypeRequirementDescription
valueTOptionalValue to reset to. Defaults to the value the watchable was created with or to the value used in the last reset.

Returns: void

unwatch

unwatch(onValueChangeCallback: OnValueChangeCallback): void

Stops triggering the specified callback on the value change.

Parameters

ParameterTypeRequirementDescription
onValueChangeCallbackOnValueChangeCallbackRequiredObserver that should not be triggered anymore

Returns: void

watch

watch(onValueChangeCallback: OnValueChangeCallback, options?: WatchOptions): UnwatchFunction

Subscribes to the value changes.

When the value is changed, the OnValueChangeCallback callback is triggered.

Returns UnwatchFunction, to unwatch observable value changes.

Parameters

ParameterTypeRequirementDescription
onValueChangeCallbackOnValueChangeCallbackRequiredObserver to be triggered when the value is changed
optionsWatchOptionsOptionalOptions

Returns: UnwatchFunction

Properties

oldValue

oldValue: T

Previous value of the observable property.

value

value: T

Current value of the observable property.