From 3423207c022d0132932402dcf26625ef20df7cb7 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Wed, 20 Nov 2019 23:18:03 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20add=20dictionary=20t?= =?UTF-8?q?ype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/stores/dictionary.ts | 11 +++++------ src/client/types/index.ts | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/client/stores/dictionary.ts b/src/client/stores/dictionary.ts index 6599ee2..a00bdab 100644 --- a/src/client/stores/dictionary.ts +++ b/src/client/stores/dictionary.ts @@ -1,9 +1,10 @@ +import { LocaleDictionary } from './../types/index' import { writable, derived } from 'svelte/store' import merge from 'deepmerge' -let dictionary: Record> +let dictionary: LocaleDictionary -const $dictionary = writable({}) +const $dictionary = writable({}) $dictionary.subscribe(newDictionary => { dictionary = newDictionary }) @@ -16,11 +17,9 @@ function hasLocaleDictionary(locale: string) { return locale in dictionary } -function addMessagesTo(locale: string, ...partials: any[]) { +function addMessagesTo(locale: string, ...partials: LocaleDictionary[]) { $dictionary.update(d => { - dictionary[locale] = merge.all( - [dictionary[locale] || {}].concat(partials) - ) + dictionary[locale] = merge.all([dictionary[locale] || {}].concat(partials)) return d }) } diff --git a/src/client/types/index.ts b/src/client/types/index.ts index 5e2d787..7fccda3 100644 --- a/src/client/types/index.ts +++ b/src/client/types/index.ts @@ -1,3 +1,7 @@ +export interface LocaleDictionary { + [key: string]: LocaleDictionary | LocaleDictionary[] | string | object +} + export interface MessageObject { id?: string locale?: string