From 3e9413db32e1a8ba80455373f1766f150f933ded Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Date: Tue, 28 May 2024 17:54:43 -0300 Subject: [PATCH] feat: remove private properties --- .changeset/afraid-spies-design.md | 10 +++++++++ packages/runtime/src/index.ts | 34 +++++++++++++++---------------- 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 .changeset/afraid-spies-design.md diff --git a/.changeset/afraid-spies-design.md b/.changeset/afraid-spies-design.md new file mode 100644 index 0000000..2763054 --- /dev/null +++ b/.changeset/afraid-spies-design.md @@ -0,0 +1,10 @@ +--- +"@diacritic/utilities": patch +"@diacritic/detector": patch +"@diacritic/runtime": patch +"@diacritic/parser": patch +"@diacritic/react": patch +"@diacritic/core": patch +--- + +Remove private properties (incompatible with React Native) diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 0c1d3b2..c924711 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -59,54 +59,54 @@ export class Diacritic { public readonly languages!: Language[]; public readonly namespaces!: Namespace[]; - #current!: Language; - #modules: Record> = {} as any; + private current!: Language; + private modules: Record> = {} as any; - #listeners: Set<(language: Language) => void> = new Set(); + private listeners: Set<(language: Language) => void> = new Set(); public constructor(registry: Registry, initialLanguage: Language = registry.defaultLanguage) { this.registry = registry; - this.#current = initialLanguage; + this.current = initialLanguage; } public t!: Proxy; public get language(): Language { - return this.#current; + return this.current; }; public setLanguage = (language: Language) => { - this.#current = language; - this.#listeners.forEach(listener => listener(language)); + this.current = language; + this.listeners.forEach(listener => listener(language)); - this.t = createProxy(this.#current, this.#modules); + this.t = createProxy(this.current, this.modules); }; public onChange = (listener: (language: Language) => void) => { - this.#listeners.add(listener); - return () => this.#listeners.delete(listener); + this.listeners.add(listener); + return () => this.listeners.delete(listener); }; public loadModules = async (languages: Language[], namespaces: Namespace[]) => { const promises: Promise[] = []; for (const language of languages) { for (const namespace of namespaces) { - if (this.#modules[language] && this.#modules[language]![namespace]) continue; - promises.push(this.#loadModule(language, namespace)); + if (this.modules[language] && this.modules[language]![namespace]) continue; + promises.push(this.loadModule(language, namespace)); } } if (promises.length === 0) return; await Promise.all(promises); - this.t = createProxy(this.#current, this.#modules); + this.t = createProxy(this.current, this.modules); }; public needToLoadModules = (languages: Language[], namespaces: Namespace[]) => { const missing = []; for (const language of languages) { for (const namespace of namespaces) { - if (this.#modules[language] && this.#modules[language]![namespace]) continue; + if (this.modules[language] && this.modules[language]![namespace]) continue; missing.push({ language, namespace }); } } @@ -114,11 +114,11 @@ export class Diacritic { return missing.length > 0; }; - async #loadModule(language: Language, namespace: Namespace) { + private async loadModule(language: Language, namespace: Namespace) { const module = await this.registry.importTranslationModule(language, namespace); - if (!this.#modules[language]) this.#modules[language] = {} as any; - this.#modules[language]![namespace] = module; + if (!this.modules[language]) this.modules[language] = {} as any; + this.modules[language]![namespace] = module; } }