| @@ -0,0 +1,8 | |||
| 
             | 
        1 | import { bundle } from "../i18n"; | |
| 
             | 
        2 | ||
| 
             | 
        3 | export const { i18n, load, define } = bundle({ | |
| 
             | 
        4 | foo: "foo", | |
| 
             | 
        5 | bar: "bar" | |
| 
             | 
        6 | }, { | |
| 
             | 
        7 | ru: () => import("./ru/nls-test") | |
| 
             | 
        8 | }); No newline at end of file | |
| @@ -0,0 +1,5 | |||
| 
             | 
        1 | import { define } from "../nls-test"; | |
| 
             | 
        2 | ||
| 
             | 
        3 | export default define({ | |
| 
             | 
        4 | foo: "Фу" | |
| 
             | 
        5 | }); No newline at end of file | |
| @@ -1,7 +1,7 | |||
| 
             | 
        1 | 1 | import { MapOf, PromiseOrValue } from "@implab/core-amd/interfaces"; | 
| 
             | 
        2 | 2 | import { argumentNotEmptyString, isPromise, mixin } from "@implab/core-amd/safe"; | 
| 
             | 
        3 | 3 | |
| 
             | 
        4 | 
            
             export type LocaleProvider<T> = () => PromiseOrValue<T | { | 
    |
| 
             | 
        4 | export type LocaleProvider<T> = () => PromiseOrValue<T | {default: T}>; | |
| 
             | 
        5 | 5 | |
| 
             | 
        6 | 6 | function when<T, T2>(value: PromiseOrValue<T>, cb: (v: T) => PromiseOrValue<T2>): PromiseOrValue<T2> { | 
| 
             | 
        7 | 7 | return isPromise(value) ? | 
| @@ -1,6 +1,6 | |||
| 
             | 
        1 | 1 | import { id as mid} from "module"; | 
| 
             | 
        2 | 
            
             import {  | 
    |
| 
             | 
        3 | 
            
             import {  | 
    |
| 
             | 
        2 | import { PromiseOrValue } from "@implab/core-amd/interfaces"; | |
| 
             | 
        3 | import { NlsBundle } from "./NlsBundle"; | |
| 
             | 
        4 | 4 | import { isPromise } from "@implab/core-amd/safe"; | 
| 
             | 
        5 | 5 | import { locale as sysLocale } from "dojo/_base/kernel"; | 
| 
             | 
        6 | 6 | import { TraceSource } from "@implab/core-amd/log/TraceSource"; | 
| @@ -14,7 +14,11 export interface OnLoad { | |||
| 
             | 
        14 | 14 | error(err: unknown): void; | 
| 
             | 
        15 | 15 | } | 
| 
             | 
        16 | 16 | |
| 
             | 
        17 | 
            
             export  | 
    |
| 
             | 
        17 | export const bundle = <T extends object>(nls: T, locales?: Record<string, () => PromiseOrValue<object>>) : { | |
| 
             | 
        18 | i18n: (locale?: string) => T; | |
| 
             | 
        19 | define: (pack: Partial<T>) => object; | |
| 
             | 
        20 | load: (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => void; | |
| 
             | 
        21 | } => { | |
| 
             | 
        18 | 22 | const nlsBundle = new NlsBundle(nls, locales); | 
| 
             | 
        19 | 23 | |
| 
             | 
        20 | 24 | const fn = (_locale?: string) => { | 
| @@ -27,7 +31,8 export function bundle<T extends object> | |||
| 
             | 
        27 | 31 | return result; | 
| 
             | 
        28 | 32 | }; | 
| 
             | 
        29 | 33 | |
| 
             | 
        30 | fn.define = (pack: Partial<T>) => pack; | |
| 
             | 
        34 | fn.i18n = fn; | |
| 
             | 
        35 | fn.define = (pack: Partial<T>): object => pack; | |
| 
             | 
        31 | 36 | fn.load = async (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => { | 
| 
             | 
        32 | 37 | const locale = id || sysLocale; | 
| 
             | 
        33 | 38 | if (config && config.isBuild) { | 
| @@ -48,4 +53,4 export function bundle<T extends object> | |||
| 
             | 
        48 | 53 | }; | 
| 
             | 
        49 | 54 | |
| 
             | 
        50 | 55 | return fn; | 
| 
             | 
        51 | } | |
| 
             | 
        56 | }; | |
| @@ -33,7 +33,7 export const isDjObservableResults = <T> | |||
| 
             | 
        33 | 33 | v && (typeof (v as { observe?: unknown; }).observe === "function"); | 
| 
             | 
        34 | 34 | |
| 
             | 
        35 | 35 | export const query = <T, Q, O>(store: Queryable<T, Q, O>, includeUpdates = true) => | 
| 
             | 
        36 | (query?: Q, options?: O & { observe: boolean }) => { | |
| 
             | 
        36 | (query?: Q, options?: O & { observe?: boolean }) => { | |
| 
             | 
        37 | 37 | return observe<OrderedUpdate<T>>(({ next, complete, error, isClosed }) => { | 
| 
             | 
        38 | 38 | try { | 
| 
             | 
        39 | 39 | const results = store.query(query, options); | 
| @@ -147,13 +147,20 export const bind = <K extends string, T | |||
| 
             | 
        147 | 147 | }; | 
| 
             | 
        148 | 148 | }; | 
| 
             | 
        149 | 149 | |
| 
             | 
        150 | /** Creates refHook to toggle the specified css class on the target element | |
| 
             | 
        151 | * | |
| 
             | 
        152 | * @param className | |
| 
             | 
        153 | * @param subj a boolean observable value. When the value is false the className | |
| 
             | 
        154 | * is removed, when the value is true, the className is added to the target element | |
| 
             | 
        155 | * @returns refHook | |
| 
             | 
        156 | */ | |
| 
             | 
        150 | 157 | export const toggleClass = (className: string, subj: Subscribable<boolean>) => { | 
| 
             | 
        151 | 158 | let h = { unsubscribe() { } }; | 
| 
             | 
        152 | 159 | return (elOrWidget: HTMLElement | _WidgetBase | undefined) => { | 
| 
             | 
        153 | 160 | const el = isWidget(elOrWidget) ? elOrWidget.domNode : elOrWidget; | 
| 
             | 
        154 | 161 | if (el) { | 
| 
             | 
        155 | 162 | h = subj.subscribe({ | 
| 
             | 
        156 | next: v => djClass.toggle(el, className, v) | |
| 
             | 
        163 | next: v => djClass.toggle(el, className, v || false) | |
| 
             | 
        157 | 164 | }); | 
| 
             | 
        158 | 165 | } else { | 
| 
             | 
        159 | 166 | h.unsubscribe(); | 
| @@ -161,6 +168,7 export const toggleClass = (className: s | |||
| 
             | 
        161 | 168 | }; | 
| 
             | 
        162 | 169 | }; | 
| 
             | 
        163 | 170 | |
| 
             | 
        171 | /** Combines multiple hooks to the single one */ | |
| 
             | 
        164 | 172 | export const all = <T, A extends JSX.Ref<T>[]>(...cbs: A): JSX.Ref<T> => (arg: T | undefined) => cbs.forEach(cb => cb(arg)); | 
| 
             | 
        165 | 173 | |
| 
             | 
        166 | 174 | /** Decorates the method which will be registered as the handle for the specified event. | 
| @@ -165,6 +165,8 export const render = (rendition: unknow | |||
| 
             | 
        165 | 165 | } | 
| 
             | 
        166 | 166 | }; | 
| 
             | 
        167 | 167 | |
| 
             | 
        168 | const emptyFragment = document.createDocumentFragment(); | |
| 
             | 
        169 | ||
| 
             | 
        168 | 170 | /** Renders DOM element for different types of the argument. */ | 
| 
             | 
        169 | 171 | export const getItemDom = (v: unknown) => { | 
| 
             | 
        170 | 172 | if (typeof v === "string" || typeof v === "number" || v instanceof RegExp || v instanceof Date) { | 
| @@ -181,7 +183,7 export const getItemDom = (v: unknown) = | |||
| 
             | 
        181 | 183 | return v.domNode; | 
| 
             | 
        182 | 184 | } else if (typeof v === "boolean" || v === null || v === undefined) { | 
| 
             | 
        183 | 185 | // null | undefined | boolean are removed | 
| 
             | 
        184 | 
            
                     return  | 
    |
| 
             | 
        186 | return emptyFragment; | |
| 
             | 
        185 | 187 | } else if (v instanceof Array) { | 
| 
             | 
        186 | 188 | // arrays will be translated to document fragments | 
| 
             | 
        187 | 189 | const fragment = document.createDocumentFragment(); | 
        
        General Comments 0
    
    
  
  
                      You need to be logged in to leave comments.
                      Login now
                    
                