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 @@ -1,7 +1,7 @@ import { MapOf, PromiseOrValue } from "@implab/core-amd/interfaces"; import { argumentNotEmptyString, isPromise, mixin } from "@implab/core-amd/safe"; -export type LocaleProvider = () => PromiseOrValue; +export type LocaleProvider = () => PromiseOrValue; function when(value: PromiseOrValue, cb: (v: T) => PromiseOrValue): PromiseOrValue { return isPromise(value) ? diff --git a/djx/src/main/ts/i18n.ts b/djx/src/main/ts/i18n.ts --- a/djx/src/main/ts/i18n.ts +++ b/djx/src/main/ts/i18n.ts @@ -1,6 +1,6 @@ import { id as mid} from "module"; -import { MapOf } from "@implab/core-amd/interfaces"; -import { LocaleProvider, NlsBundle } from "./NlsBundle"; +import { PromiseOrValue } from "@implab/core-amd/interfaces"; +import { NlsBundle } from "./NlsBundle"; import { isPromise } from "@implab/core-amd/safe"; import { locale as sysLocale } from "dojo/_base/kernel"; import { TraceSource } from "@implab/core-amd/log/TraceSource"; @@ -14,7 +14,11 @@ export interface OnLoad { error(err: unknown): void; } -export function bundle(nls: T, locales?: MapOf>) { +export const bundle = (nls: T, locales?: Record PromiseOrValue>) : { + i18n: (locale?: string) => T; + define: (pack: Partial) => object; + load: (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => void; +} => { const nlsBundle = new NlsBundle(nls, locales); const fn = (_locale?: string) => { @@ -27,7 +31,8 @@ export function bundle return result; }; - fn.define = (pack: Partial) => pack; + fn.i18n = fn; + fn.define = (pack: Partial): object => pack; fn.load = async (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => { const locale = id || sysLocale; if (config && config.isBuild) { @@ -48,4 +53,4 @@ export function bundle }; return fn; -} +}; diff --git a/djx/src/main/ts/store.ts b/djx/src/main/ts/store.ts --- a/djx/src/main/ts/store.ts +++ b/djx/src/main/ts/store.ts @@ -33,7 +33,7 @@ export const isDjObservableResults = v && (typeof (v as { observe?: unknown; }).observe === "function"); export const query = (store: Queryable, includeUpdates = true) => - (query?: Q, options?: O & { observe: boolean }) => { + (query?: Q, options?: O & { observe?: boolean }) => { return observe>(({ next, complete, error, isClosed }) => { try { const results = store.query(query, options); diff --git a/djx/src/main/ts/tsx.ts b/djx/src/main/ts/tsx.ts --- a/djx/src/main/ts/tsx.ts +++ b/djx/src/main/ts/tsx.ts @@ -147,13 +147,20 @@ export const bind = ) => { let h = { unsubscribe() { } }; return (elOrWidget: HTMLElement | _WidgetBase | undefined) => { const el = isWidget(elOrWidget) ? elOrWidget.domNode : elOrWidget; if (el) { h = subj.subscribe({ - next: v => djClass.toggle(el, className, v) + next: v => djClass.toggle(el, className, v || false) }); } else { h.unsubscribe(); @@ -161,6 +168,7 @@ export const toggleClass = (className: s }; }; +/** Combines multiple hooks to the single one */ export const all = []>(...cbs: A): JSX.Ref => (arg: T | undefined) => cbs.forEach(cb => cb(arg)); /** Decorates the method which will be registered as the handle for the specified event. diff --git a/djx/src/main/ts/tsx/render.ts b/djx/src/main/ts/tsx/render.ts --- a/djx/src/main/ts/tsx/render.ts +++ b/djx/src/main/ts/tsx/render.ts @@ -165,6 +165,8 @@ export const render = (rendition: unknow } }; +const emptyFragment = document.createDocumentFragment(); + /** Renders DOM element for different types of the argument. */ export const getItemDom = (v: unknown) => { if (typeof v === "string" || typeof v === "number" || v instanceof RegExp || v instanceof Date) { @@ -181,7 +183,7 @@ export const getItemDom = (v: unknown) = return v.domNode; } else if (typeof v === "boolean" || v === null || v === undefined) { // null | undefined | boolean are removed - return document.createDocumentFragment(); + return emptyFragment; } else if (v instanceof Array) { // arrays will be translated to document fragments const fragment = document.createDocumentFragment(); diff --git a/djx/src/test/ts/nls/nls-test.ts b/djx/src/test/ts/nls/nls-test.ts new file mode 100644 --- /dev/null +++ b/djx/src/test/ts/nls/nls-test.ts @@ -0,0 +1,8 @@ +import { bundle } from "../i18n"; + +export const { i18n, load, define } = bundle({ + foo: "foo", + bar: "bar" +}, { + ru: () => import("./ru/nls-test") +}); \ No newline at end of file diff --git a/djx/src/test/ts/nls/ru/nls-test.ts b/djx/src/test/ts/nls/ru/nls-test.ts new file mode 100644 --- /dev/null +++ b/djx/src/test/ts/nls/ru/nls-test.ts @@ -0,0 +1,5 @@ +import { define } from "../nls-test"; + +export default define({ + foo: "Фу" +}); \ No newline at end of file diff --git a/djx/src/test/ts/view/MyWidget.tsx b/djx/src/test/ts/view/MyWidget.tsx --- a/djx/src/test/ts/view/MyWidget.tsx +++ b/djx/src/test/ts/view/MyWidget.tsx @@ -76,7 +76,7 @@ export class MyWidget extends djbase(Djx } @on("count-inc") - private _onCounterInc(evt: Event & { detail: number; x?: number; }) { + protected _onCounterInc(evt: Event & { detail: number; x?: number; }) { argumentNotNull(evt, "evt"); } 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.6.2", "dev": true, "license": "BSD-2-Clause", "peerDependencies": {