diff --git a/djx/src/main/ts/NlsBundle.ts b/djx/src/main/ts/NlsBundle.ts --- a/djx/src/main/ts/NlsBundle.ts +++ b/djx/src/main/ts/NlsBundle.ts @@ -9,8 +9,14 @@ function when(value: PromiseOrVal cb(value); } -const chainObjects = (o1: T, o2: T2) => - mixin(Object.create(o1) as T, o2); +const loadPackage = (localeData: LocaleProvider> | undefined) => + localeData ? + when(localeData(), data => data && "default" in data ? data.default : data) : + undefined; + +const chainObjects = (o1: T, o2: Partial | undefined): T => + o2 ? mixin(Object.create(o1) as T, o2) : o1; + export class NlsBundle { private readonly _locales: MapOf>>; @@ -44,15 +50,11 @@ export class NlsBundle if (this._cache[locale]) return this._cache[locale]; - const data = this._loadPackage(this._locales[locale]); + const data = loadPackage(this._locales[locale]); const parent = this._resolveLocale(locales); return this._cache[locale] = when(data, x => { return when(parent, y => this._cache[locale] = chainObjects(y, x)); }); } - - _loadPackage(localeData: LocaleProvider>) { - return when(localeData(), data => data && "default" in data ? data.default : data); - } } diff --git a/djx/src/main/ts/tsx/DjxFragment.ts b/djx/src/main/ts/tsx/DjxFragment.ts --- a/djx/src/main/ts/tsx/DjxFragment.ts +++ b/djx/src/main/ts/tsx/DjxFragment.ts @@ -1,7 +1,11 @@ +import { FunctionRendition } from "./FunctionRendition"; +import { getItemDom } from "./render"; + /** Special functional component used to create a document fragment */ -export function DjxFragment({ children }: { children?: Node | Node[] }) { - const fragment = document.createDocumentFragment(); - if (children) - (children instanceof Array ? children : [children]).forEach(child => fragment.appendChild(child)); - return fragment; -} \ No newline at end of file +export const DjxFragment = ({ children }: { children?: unknown | unknown[] }) => + new FunctionRendition(() => { + const fragment = document.createDocumentFragment(); + if (children) + (children instanceof Array ? children : [children]).map(getItemDom).forEach(child => fragment.appendChild(child)); + return fragment; + }); \ No newline at end of file diff --git a/djx/src/main/ts/tsx/DjxWidgetBase.ts b/djx/src/main/ts/tsx/DjxWidgetBase.ts --- a/djx/src/main/ts/tsx/DjxWidgetBase.ts +++ b/djx/src/main/ts/tsx/DjxWidgetBase.ts @@ -1,11 +1,12 @@ import { djbase, djclass } from "../declare"; import _WidgetBase = require("dijit/_WidgetBase"); import _AttachMixin = require("dijit/_AttachMixin"); -import { Rendition, isNode, isElementNode } from "./traits"; +import { isNode, isElementNode } from "./traits"; import registry = require("dijit/registry"); import on = require("dojo/on"); import { Scope } from "./Scope"; import { render } from "./render"; +import { isNull } from "@implab/core-amd/safe"; // type Handle = dojo.Handle; @@ -70,7 +71,7 @@ export abstract class DjxWidgetBase( baseNode: T, - getAttrFunc: (baseNode: T, attr: string) => string, + getAttrFunc: (baseNode: T, attr: string) => string | undefined, // tslint:disable-next-line: ban-types attachFunc: (node: T, type: string, func?: (...args: unknown[]) => unknown) => dojo.Handle ): boolean { @@ -92,7 +93,10 @@ export abstract class DjxWidgetBase String(n.get(p as keyof typeof n)), // callback to get a property of a widget + (n, p) => { + const v = n.get(p as keyof typeof n); + return isNull(v) ? undefined : String(v); + }, // callback to get a property of a widget (widget, type, callback) => { if (!callback) throw new Error("The callback must be specified"); @@ -112,7 +116,7 @@ export abstract class DjxWidgetBase dojo.Handle); + return super._processTemplateNode(baseNode, getAttrFunc as (baseNode: T, attr: string) => string, attachFunc as (node: T, type: string, func?: Function) => dojo.Handle); } /** Starts current widget and all its supporting widgets (placed outside diff --git a/djx/src/main/ts/tsx/RenditionBase.ts b/djx/src/main/ts/tsx/RenditionBase.ts --- a/djx/src/main/ts/tsx/RenditionBase.ts +++ b/djx/src/main/ts/tsx/RenditionBase.ts @@ -59,7 +59,7 @@ export abstract class RenditionBase startupWidgets(n)); } diff --git a/playground/package-lock.json b/playground/package-lock.json --- a/playground/package-lock.json +++ b/playground/package-lock.json @@ -30,6 +30,7 @@ }, "../djx/build/npm/package": { "name": "@implab/djx", + "version": "1.4.4", "dev": true, "license": "BSD-2-Clause", "peerDependencies": {