Adding custom check function for await store
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import Observable, { ObserverCallback } from "./observable";
|
||||
|
||||
export type CheckFunction<T> = (val: T) => boolean;
|
||||
|
||||
export default class AwaitStore<T = any> {
|
||||
private observable = new Observable<T>();
|
||||
constructor(private _value: T) {
|
||||
@ -49,7 +51,7 @@ export default class AwaitStore<T = any> {
|
||||
* @param val Value to await
|
||||
*/
|
||||
awaitValue(
|
||||
val: T
|
||||
val: T | CheckFunction<T>
|
||||
): PromiseLike<void> & {
|
||||
catch: (cb: (err: any) => PromiseLike<void>) => PromiseLike<void>;
|
||||
ignore: () => void;
|
||||
@ -58,7 +60,12 @@ export default class AwaitStore<T = any> {
|
||||
|
||||
let prms = new Promise<void>((yes) => {
|
||||
const cb = () => {
|
||||
if (this._value === val) {
|
||||
if (typeof val === "function") {
|
||||
if ((val as CheckFunction<T>)(this._value)) {
|
||||
yes();
|
||||
this.unsubscribe(cb);
|
||||
}
|
||||
} else if (this._value === val) {
|
||||
yes();
|
||||
this.unsubscribe(cb);
|
||||
}
|
||||
|
Reference in New Issue
Block a user