@thi.ng/rdom
Version:
Lightweight, reactive, VDOM-less UI/DOM components with async lifecycle and @thi.ng/hiccup compatible
28 lines (27 loc) • 633 B
JavaScript
import { Component } from "./component.js";
const $promise = (prom, error) => new $Promise(prom, error);
class $Promise extends Component {
constructor(promise, error = (e) => e) {
super();
this.promise = promise;
this.error = error;
}
inner;
async mount(parent, index) {
try {
this.inner = this.$compile(await this.promise);
} catch (e) {
this.inner = this.$compile(this.error(e));
}
return this.el = await this.inner.mount(parent, index);
}
async unmount() {
await this.inner.unmount();
this.inner = void 0;
this.el = void 0;
}
}
export {
$Promise,
$promise
};