##// END OF EJS Templates
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already

File last commit:

r118:e07418577cbc v1.6.1 default
r131:c7d9ad82b374 v1.8.1 default
Show More
WatchRendition.ts
98 lines | 2.9 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
added whenRendered() method to wait for pending oprations to complete
r118 import { getItemDom, getScope, scheduleRender } from "./render";
cin
Added Renderer, WatchRendition
r94 import { RenditionBase } from "./RenditionBase";
cin
Testing nested watch, release candidate
r101 import { Scope } from "./Scope";
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 import { Subscribable } from "../observable";
import { Cancellation } from "@implab/core-amd/Cancellation";
import { collectNodes, destroy, isDocumentFragmentNode, isMounted, placeAt, startupWidgets } 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
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 private readonly _node: Node;
cin
Added Renderer, WatchRendition
r94
private readonly _scope = new Scope();
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 private readonly _subject: Subscribable<T>;
private _renderJob?: { value: T };
cin
refactoring, adding scope to rendering methods
r96
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 private _ct = Cancellation.none;
constructor(component: (arg: T) => unknown, subject: Subscribable<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
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 this._node = document.createComment("[Watch]");
cin
Added Renderer, WatchRendition
r94 }
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 protected _create() {
cin
Testing nested watch, release candidate
r101 const scope = getScope();
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 scope.own(() => {
this._scope.destroy();
destroy(this._node);
});
scope.own(this._subject.subscribe({ next: this._onValue }));
this._ct = new Cancellation(cancel => scope.own(cancel));
}
cin
Working on WatchForRendition
r107 private readonly _onValue = (value: T) => {
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 if (!this._renderJob) {
// schedule a new job
this._renderJob = { value };
this._render().catch(e => trace.error(e));
} else {
// update existing job
this._renderJob = { value };
}
cin
Working on WatchForRendition
r107 };
cin
Added Renderer, WatchRendition
r94
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 private async _render() {
cin
added whenRendered() method to wait for pending oprations to complete
r118 const beginRender = await scheduleRender(this._scope);
const endRender = beginRender();
try {
// don't render destroyed rendition
if (this._ct.isRequested())
return;
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
cin
added whenRendered() method to wait for pending oprations to complete
r118 // remove all previous content
this._scope.clean();
cin
refactoring, adding scope to rendering methods
r96
cin
added whenRendered() method to wait for pending oprations to complete
r118 // render the new node
const node = getItemDom(this._renderJob ? this._component(this._renderJob.value) : undefined);
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
cin
added whenRendered() method to wait for pending oprations to complete
r118 // get actual content
const pending = isDocumentFragmentNode(node) ?
collectNodes(node.childNodes) :
[node];
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
cin
added whenRendered() method to wait for pending oprations to complete
r118 placeAt(node, this._node, "after");
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
cin
added whenRendered() method to wait for pending oprations to complete
r118 if (isMounted(this._node))
pending.forEach(n => startupWidgets(n));
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
cin
added whenRendered() method to wait for pending oprations to complete
r118 if (pending.length)
this._scope.own(() => pending.forEach(destroy));
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
cin
added whenRendered() method to wait for pending oprations to complete
r118 this._renderJob = undefined;
} finally {
endRender();
}
cin
Added Renderer, WatchRendition
r94 }
protected _getDomNode() {
if (!this._node)
throw new Error("The instance of the widget isn't created");
return this._node;
}
}