element-vir
Version:
Heroic. Reactive. Declarative. Type safe. Web components without compromise.
53 lines (52 loc) • 1.76 kB
JavaScript
import { CallbackObservable } from 'observavir';
/**
* Class for constructing async props. Do not use this directly as its internal types won't be
* inferred correctly. Instead use {@link asyncProp} an async prop or {@link AsyncProp} for types.
*
* @category Internal
*/
export class InternalAsyncPropClass extends CallbackObservable {
/**
* Checks if the current `.value` has resolved (meaning the Promise has settled and it was not
* rejected). This type guards the current instance's `.value` property.
*/
isResolved() {
return !(this.value instanceof Promise);
}
/**
* Checks if the current `.value` has settled (meaning it is either a rejection error or a
* resolved value). This type guards the current instance's `.value` property.
*/
isSettled() {
return !(this.value instanceof Promise);
}
/**
* Checks if the current `.value` has not settled yet settled (meaning it is still an unsettled
* Promise). This type guards the current instance's `.value` property.
*/
isWaiting() {
return this.value instanceof Promise;
}
/**
* Checks if the current `.value` is a rejection error. This type guards the current instance's
* `.value` property.
*/
isError() {
return this.value instanceof Error;
}
/**
* Checks if the current `.value` is resolved (and not an error) or still waiting. This type
* guards the current instance's `.value` property.
*/
isNotError() {
return !(this.value instanceof Error);
}
}
/**
* Create an async prop for a declarative element's state.
*
* @category Async
*/
export function asyncProp(init) {
return new InternalAsyncPropClass(init);
}