@@ -9,8 +9,14 function when<T, T2>(value: PromiseOrVal | |||
|
9 | 9 | cb(value); |
|
10 | 10 | } |
|
11 | 11 | |
|
12 | const chainObjects = <T extends object, T2 extends object>(o1: T, o2: T2) => | |
|
13 | mixin(Object.create(o1) as T, o2); | |
|
12 | const loadPackage = <T extends object>(localeData: LocaleProvider<Partial<T>> | undefined) => | |
|
13 | localeData ? | |
|
14 | when(localeData(), data => data && "default" in data ? data.default : data) : | |
|
15 | undefined; | |
|
16 | ||
|
17 | const chainObjects = <T extends object>(o1: T, o2: Partial<T> | undefined): T => | |
|
18 | o2 ? mixin(Object.create(o1) as T, o2) : o1; | |
|
19 | ||
|
14 | 20 | export class NlsBundle<T extends object> { |
|
15 | 21 | private readonly _locales: MapOf<LocaleProvider<Partial<T>>>; |
|
16 | 22 | |
@@ -44,15 +50,11 export class NlsBundle<T extends object> | |||
|
44 | 50 | if (this._cache[locale]) |
|
45 | 51 | return this._cache[locale]; |
|
46 | 52 | |
|
47 |
const data = |
|
|
53 | const data = loadPackage(this._locales[locale]); | |
|
48 | 54 | const parent = this._resolveLocale(locales); |
|
49 | 55 | |
|
50 | 56 | return this._cache[locale] = when(data, x => { |
|
51 | 57 | return when(parent, y => this._cache[locale] = chainObjects(y, x)); |
|
52 | 58 | }); |
|
53 | 59 | } |
|
54 | ||
|
55 | _loadPackage(localeData: LocaleProvider<Partial<T>>) { | |
|
56 | return when(localeData(), data => data && "default" in data ? data.default : data); | |
|
57 | } | |
|
58 | 60 | } |
@@ -1,7 +1,11 | |||
|
1 | import { FunctionRendition } from "./FunctionRendition"; | |
|
2 | import { getItemDom } from "./render"; | |
|
3 | ||
|
1 | 4 | /** Special functional component used to create a document fragment */ |
|
2 |
export |
|
|
3 | const fragment = document.createDocumentFragment(); | |
|
4 | if (children) | |
|
5 | (children instanceof Array ? children : [children]).forEach(child => fragment.appendChild(child)); | |
|
6 | return fragment; | |
|
7 | } No newline at end of file | |
|
5 | export const DjxFragment = ({ children }: { children?: unknown | unknown[] }) => | |
|
6 | new FunctionRendition(() => { | |
|
7 | const fragment = document.createDocumentFragment(); | |
|
8 | if (children) | |
|
9 | (children instanceof Array ? children : [children]).map(getItemDom).forEach(child => fragment.appendChild(child)); | |
|
10 | return fragment; | |
|
11 | }); No newline at end of file |
@@ -1,11 +1,12 | |||
|
1 | 1 | import { djbase, djclass } from "../declare"; |
|
2 | 2 | import _WidgetBase = require("dijit/_WidgetBase"); |
|
3 | 3 | import _AttachMixin = require("dijit/_AttachMixin"); |
|
4 |
import { |
|
|
4 | import { isNode, isElementNode } from "./traits"; | |
|
5 | 5 | import registry = require("dijit/registry"); |
|
6 | 6 | import on = require("dojo/on"); |
|
7 | 7 | import { Scope } from "./Scope"; |
|
8 | 8 | import { render } from "./render"; |
|
9 | import { isNull } from "@implab/core-amd/safe"; | |
|
9 | 10 | |
|
10 | 11 | // type Handle = dojo.Handle; |
|
11 | 12 | |
@@ -70,7 +71,7 export abstract class DjxWidgetBase<Attr | |||
|
70 | 71 | } |
|
71 | 72 | } |
|
72 | 73 | |
|
73 |
abstract render(): |
|
|
74 | abstract render(): JSX.Element; | |
|
74 | 75 | |
|
75 | 76 | private _connectEventHandlers() { |
|
76 | 77 | if (this._eventHandlers) |
@@ -83,7 +84,7 export abstract class DjxWidgetBase<Attr | |||
|
83 | 84 | |
|
84 | 85 | _processTemplateNode<T extends (Element | Node | _WidgetBase)>( |
|
85 | 86 | baseNode: T, |
|
86 | getAttrFunc: (baseNode: T, attr: string) => string, | |
|
87 | getAttrFunc: (baseNode: T, attr: string) => string | undefined, | |
|
87 | 88 | // tslint:disable-next-line: ban-types |
|
88 | 89 | attachFunc: (node: T, type: string, func?: (...args: unknown[]) => unknown) => dojo.Handle |
|
89 | 90 | ): boolean { |
@@ -92,7 +93,10 export abstract class DjxWidgetBase<Attr | |||
|
92 | 93 | if (w) { |
|
93 | 94 | // from dijit/_WidgetsInTemplateMixin |
|
94 | 95 | this._processTemplateNode(w, |
|
95 | (n, p) => String(n.get(p as keyof typeof n)), // callback to get a property of a widget | |
|
96 | (n, p) => { | |
|
97 | const v = n.get(p as keyof typeof n); | |
|
98 | return isNull(v) ? undefined : String(v); | |
|
99 | }, // callback to get a property of a widget | |
|
96 | 100 | (widget, type, callback) => { |
|
97 | 101 | if (!callback) |
|
98 | 102 | throw new Error("The callback must be specified"); |
@@ -112,7 +116,7 export abstract class DjxWidgetBase<Attr | |||
|
112 | 116 | } |
|
113 | 117 | } |
|
114 | 118 | // eslint-disable-next-line @typescript-eslint/ban-types |
|
115 | return super._processTemplateNode(baseNode, getAttrFunc, attachFunc as (node: T, type: string, func?: Function) => dojo.Handle); | |
|
119 | return super._processTemplateNode(baseNode, getAttrFunc as (baseNode: T, attr: string) => string, attachFunc as (node: T, type: string, func?: Function) => dojo.Handle); | |
|
116 | 120 | } |
|
117 | 121 | |
|
118 | 122 | /** Starts current widget and all its supporting widgets (placed outside |
General Comments 0
You need to be logged in to leave comments.
Login now