Skip to main content

Observer

Creates a mutable ref object. You can access the .current value and detect the value change through .subscribe.

class Observer<Value = any>

Properties

return the current value.

Methods

When the current value changes, the callback function is called.

Cancel the registered subscription through callback.

Constructor

new Observer<Value>(value: Value): Observer<Value>

Parameters

value

Value

Properties

current

current

Value

return the current value.

Methods

subscribe

subscribe

Observer<Value>

subscribe(callback: ((value: Value, prevValue: Value) => void)): Observer<Value>

When the current value changes, the callback function is called.

Parameters

callback

((value: Value, prevValue: Value) => void)

unsubscribe

unsubscribe

Observer<Value>

unsubscribe(callback: ((value: Value, prevValue: Value) => void)): Observer<Value>

Cancel the registered subscription through callback.

Parameters

callback

((value: Value, prevValue: Value) => void)