##// END OF EJS Templates
corrected tear down logic handling in observables. Added support for observable query results
corrected tear down logic handling in observables. Added support for observable query results

File last commit:

r109:4a375b9c654a default
r110:1a190b3a757d v1.4.0 default
Show More
DjxWidgetBase.ts
131 lines | 4.7 KiB | video/mp2t | TypeScriptLexer
/ djx / src / main / ts / tsx / DjxWidgetBase.ts
cin
minor fix
r83 import { djbase, djclass } from "../declare";
cin
Converted to subproject djx, removed dojo-typings
r65 import _WidgetBase = require("dijit/_WidgetBase");
import _AttachMixin = require("dijit/_AttachMixin");
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 import { Rendition, isNode, isElementNode } from "./traits";
cin
Converted to subproject djx, removed dojo-typings
r65 import registry = require("dijit/registry");
cin
@on decorator registers handlers directry on domNode, added support to multiple events in one decorator...
r85 import on = require("dojo/on");
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 import { Scope } from "./Scope";
import { render } from "./render";
cin
Converted to subproject djx, removed dojo-typings
r65
// type Handle = dojo.Handle;
export interface EventArgs {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
}
cin
linting
r109 // eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface DjxWidgetBase<Attrs = object, Events extends { [name in keyof Events]: Event } = object> extends
cin
Switched to @implab/dojo-typings
r71 _WidgetBase<Events> {
cin
temp commit, working on @on() decorator
r72
cin
implemented @on("event-name") decorator for event handlers
r73 /** This property is declared only for type inference to work, it is never assigned
* and should not be used.
*/
cin
temp commit, working on @on() decorator
r72 readonly _eventMap: Events & GlobalEventHandlersEventMap;
cin
fixed DjxWidgetBase._eventHandlers initialization
r81
/** The list of pairs of event and method names. When the widget is created all methods from
* this list will be connected to corresponding events.
*
* This property is maintained in the prototype
*/
_eventHandlers: Array<{
eventName: string,
cin
linting
r109 handlerMethod: string;
cin
fixed DjxWidgetBase._eventHandlers initialization
r81 }>;
cin
Switched to @implab/dojo-typings
r71 }
cin
Converted to subproject djx, removed dojo-typings
r65
cin
Switched to @implab/dojo-typings
r71 type _super = {
startup(): void;
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
destroy(preserveDom?: boolean): void;
cin
fixed tslint errors, added support for private methods to @on() decorator
r79 };
cin
Converted to subproject djx, removed dojo-typings
r65
@djclass
cin
linting
r109 // eslint-disable-next-line @typescript-eslint/no-unused-vars
export abstract class DjxWidgetBase<Attrs = object, Events = object> extends djbase<_super, _AttachMixin>(_WidgetBase, _AttachMixin) {
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 private readonly _scope = new Scope();
cin
Converted to subproject djx, removed dojo-typings
r65
buildRendering() {
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 const node = render(this.render(), this._scope);
if (!isElementNode(node))
throw new Error("The render method must return a single DOM element");
this.domNode = node as HTMLElement;
cin
Converted to subproject djx, removed dojo-typings
r65 super.buildRendering();
// now we should get assigned data-dojo-attach-points
// place the contents of the original srcNode to the containerNode
const src = this.srcNodeRef;
const dest = this.containerNode;
cin
implemented @on("event-name") decorator for event handlers
r73 // the donNode is constructed now we need to connect event handlers
this._connectEventHandlers();
cin
Converted to subproject djx, removed dojo-typings
r65 if (src && dest) {
while (src.firstChild)
dest.appendChild(src.firstChild);
}
}
cin
linting
r109 abstract render(): Rendition;
cin
Converted to subproject djx, removed dojo-typings
r65
cin
temp commit, working on @on() decorator
r72 private _connectEventHandlers() {
cin
minor fix
r83 if (this._eventHandlers)
this._eventHandlers.forEach(({ eventName, handlerMethod }) => {
const handler = this[handlerMethod as keyof this];
if (typeof handler === "function")
cin
linting
r109 on(this.domNode, eventName, handler.bind(this) as (...args: unknown[]) => unknown);
cin
minor fix
r83 });
cin
temp commit, working on @on() decorator
r72 }
cin
Converted to subproject djx, removed dojo-typings
r65 _processTemplateNode<T extends (Element | Node | _WidgetBase)>(
baseNode: T,
cin
linting
r109 getAttrFunc: (baseNode: T, attr: string) => string,
cin
Converted to subproject djx, removed dojo-typings
r65 // tslint:disable-next-line: ban-types
cin
linting
r109 attachFunc: (node: T, type: string, func?: (...args: unknown[]) => unknown) => dojo.Handle
cin
Converted to subproject djx, removed dojo-typings
r65 ): boolean {
if (isNode(baseNode)) {
const w = registry.byNode(baseNode);
if (w) {
// from dijit/_WidgetsInTemplateMixin
this._processTemplateNode(w,
cin
linting
r109 (n, p) => String(n.get(p as keyof typeof n)), // callback to get a property of a widget
cin
Converted to subproject djx, removed dojo-typings
r65 (widget, type, callback) => {
if (!callback)
throw new Error("The callback must be specified");
// callback to do data-dojo-attach-event to a widget
if (type in widget) {
// back-compat, remove for 2.0
return widget.connect(widget, type, callback as EventListener);
} else {
// 1.x may never hit this branch, but it's the default for 2.0
cin
linting
r109 return widget.on(type as keyof GlobalEventHandlersEventMap, callback);
cin
Converted to subproject djx, removed dojo-typings
r65 }
});
// don't process widgets internals
return false;
}
}
cin
linting
r109 // eslint-disable-next-line @typescript-eslint/ban-types
return super._processTemplateNode(baseNode, getAttrFunc, attachFunc as (node: T, type: string, func?: Function) => dojo.Handle);
cin
Converted to subproject djx, removed dojo-typings
r65 }
/** Starts current widget and all its supporting widgets (placed outside
* `containerNode`) and child widgets (placed inside `containerNode`)
*/
startup() {
// startup supporting widgets
registry.findWidgets(this.domNode, this.containerNode).forEach(w => w.startup());
super.startup();
}
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
destroy(preserveDom?: boolean) {
this._scope.destroy();
super.destroy(preserveDom);
}
cin
Converted to subproject djx, removed dojo-typings
r65 }