Adding JSDoc comments to awaiter
This commit is contained in:
parent
811b03fd1b
commit
2545f3a050
@ -7,24 +7,47 @@ export default class AwaitStore<T = any> {
|
|||||||
this.unsubscribe = this.unsubscribe.bind(this);
|
this.unsubscribe = this.unsubscribe.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current value
|
||||||
|
*/
|
||||||
get value() {
|
get value() {
|
||||||
return this._value;
|
return this._value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a new value and notify subscribers
|
||||||
|
* @param value Value to be set
|
||||||
|
*/
|
||||||
send(value: T) {
|
send(value: T) {
|
||||||
this._value = value;
|
this._value = value;
|
||||||
this.observable.send(value);
|
this.observable.send(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current value as well as all changes
|
||||||
|
* @param handler Handler called on change
|
||||||
|
*/
|
||||||
subscribe(handler: ObserverCallback<T>) {
|
subscribe(handler: ObserverCallback<T>) {
|
||||||
handler(this._value);
|
handler(this._value);
|
||||||
return this.observable.subscribe(handler);
|
return this.observable.subscribe(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsubscribe from changes
|
||||||
|
* @param handler The handler to unsubscribe
|
||||||
|
*/
|
||||||
unsubscribe(handler: ObserverCallback<T>) {
|
unsubscribe(handler: ObserverCallback<T>) {
|
||||||
this.observable.unsubscribe(handler);
|
this.observable.unsubscribe(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Await a specific value and return.
|
||||||
|
*
|
||||||
|
* For example if val = true then this function would block until the value
|
||||||
|
* is actually true. If it is true, then the promise will resolve immediatly
|
||||||
|
*
|
||||||
|
* @param val Value to await
|
||||||
|
*/
|
||||||
awaitValue(val: T): PromiseLike<void> & { catch: (cb: (err: any) => PromiseLike<void>) => PromiseLike<void>, ignore: () => void } {
|
awaitValue(val: T): PromiseLike<void> & { catch: (cb: (err: any) => PromiseLike<void>) => PromiseLike<void>, ignore: () => void } {
|
||||||
|
|
||||||
let ignore: () => void = () => undefined;
|
let ignore: () => void = () => undefined;
|
||||||
@ -62,6 +85,9 @@ export default class AwaitStore<T = any> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close this store. All subscribers will be unsubscribed and any further operations will fail
|
||||||
|
*/
|
||||||
close() {
|
close() {
|
||||||
this.observable.close();
|
this.observable.close();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user