Class: Subscribable<Values>
A class that allows you to subscribe to changes in a set of values.
Example
const subscribable = new Subscribable({ foo: "bar" });
const unsubscribe = subscribable.subscribe("foo", v => console.log(v));
subscribable.set("foo", "baz"); // "baz"
unsubscribe();
subscribable.set("foo", "qux"); // nothing
Type parameters
Name | Type |
---|---|
Values | extends object = any |
Table of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• new Subscribable<Values
>(_values
)
Type parameters
Name | Type |
---|---|
Values | extends object = any |
Parameters
Name | Type | Description |
---|---|---|
_values | Values | The values to subscribe to |
Properties
_listeners
• Private
_listeners: { [K in string | number | symbol]?: Function[] } = {}
Listeners for each value
_values
• Private
_values: Values
The values to subscribe to
Accessors
_subscribableValues
• get
_subscribableValues(): Values
Gets all values
Returns
Values
Methods
_unsubscribe
▸ Private
_unsubscribe<K
>(key
, listener
): void
Unsubscribes from a value
Type parameters
Name | Type |
---|---|
K | extends string | number | symbol |
Parameters
Name | Type |
---|---|
key | K |
listener | (v : Values [K ]) => void |
Returns
void
get
▸ get<K
>(key
): Values
[K
]
Gets a value
Type parameters
Name | Type |
---|---|
K | extends string | number | symbol |
Parameters
Name | Type |
---|---|
key | K |
Returns
Values
[K
]
set
▸ Protected
set<K
>(key
, v
): Values
[K
]
Sets a value and notifies all listeners
Type parameters
Name | Type |
---|---|
K | extends string | number | symbol |
Parameters
Name | Type |
---|---|
key | K |
v | Values [K ] |
Returns
Values
[K
]
subscribe
▸ subscribe<K
>(key
, listener
): () => void
Subscribes to a value
Type parameters
Name | Type |
---|---|
K | extends string | number | symbol |
Parameters
Name | Type |
---|---|
key | K |
listener | (v : Values [K ]) => void |
Returns
fn
▸ (): void
Subscribes to a value
Returns
void