##// END OF EJS Templates
Testing nested watch, release candidate
Testing nested watch, release candidate

File last commit:

r101:bb6b1db1b430 v1.3
r101:bb6b1db1b430 v1.3
Show More
WatchRendition.ts
55 lines | 1.6 KiB | video/mp2t | TypeScriptLexer
/ djx / src / main / ts / tsx / WatchRendition.ts
cin
Added Renderer, WatchRendition
r94 import { id as mid } from "module";
import { TraceSource } from "@implab/core-amd/log/TraceSource";
import { argumentNotNull } from "@implab/core-amd/safe";
cin
Testing nested watch, release candidate
r101 import { getScope, render } from "./render";
cin
Added Renderer, WatchRendition
r94 import { RenditionBase } from "./RenditionBase";
cin
Testing nested watch, release candidate
r101 import { Scope } from "./Scope";
cin
refactoring, adding scope to rendering methods
r96 import { Observable } from "../observable";
cin
Testing nested watch, release candidate
r101 import { destroy } from "./traits";
cin
Added Renderer, WatchRendition
r94
const trace = TraceSource.get(mid);
export class WatchRendition<T> extends RenditionBase<Node> {
cin
file rename
r98 private readonly _component: (arg: T) => unknown;
cin
Added Renderer, WatchRendition
r94
private _node: Node;
private readonly _scope = new Scope();
cin
refactoring, adding scope to rendering methods
r96 private readonly _subject: Observable<T>;
cin
file rename
r98 constructor(component: (arg: T) => unknown, subject: Observable<T>) {
cin
Added Renderer, WatchRendition
r94 super();
argumentNotNull(component, "component");
cin
file rename
r98 this._component = component;
cin
Added Renderer, WatchRendition
r94
cin
refactoring, adding scope to rendering methods
r96 this._subject = subject;
cin
Added Renderer, WatchRendition
r94 this._node = document.createComment("WatchRendition placeholder");
}
cin
Testing nested watch, release candidate
r101 protected _create(attrs: object, children: any[]) {
const scope = getScope();
cin
Added Renderer, WatchRendition
r94 scope.own(this._scope);
cin
Added playground project
r97 scope.own(this._subject.on({ next: this._onValue }));
cin
Added Renderer, WatchRendition
r94 }
cin
file rename
r98 private _onValue = (value: T) =>
void this._render(value).catch( e => trace.error(e));
cin
refactoring, adding scope to rendering methods
r96
cin
Added Renderer, WatchRendition
r94 private async _render(value: T) {
this._scope.clean();
cin
Testing nested watch, release candidate
r101 const [refNode, ...rest] = await render(this._component(value), this._node, "replace", this._scope);
this._node = refNode;
this._scope.own(() => rest.forEach(destroy));
cin
Added Renderer, WatchRendition
r94 }
protected _getDomNode() {
if (!this._node)
throw new Error("The instance of the widget isn't created");
return this._node;
}
}