refactor: 💡 add dictionary type

This commit is contained in:
Christian Kaisermann 2019-11-20 23:18:03 -03:00
parent 02720aa6b6
commit 3423207c02
2 changed files with 9 additions and 6 deletions

View File

@ -1,9 +1,10 @@
import { LocaleDictionary } from './../types/index'
import { writable, derived } from 'svelte/store'
import merge from 'deepmerge'
let dictionary: Record<string, Record<string, any>>
let dictionary: LocaleDictionary
const $dictionary = writable<typeof dictionary>({})
const $dictionary = writable<LocaleDictionary>({})
$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<any>(
[dictionary[locale] || {}].concat(partials)
)
dictionary[locale] = merge.all([dictionary[locale] || {}].concat(partials))
return d
})
}

View File

@ -1,3 +1,7 @@
export interface LocaleDictionary {
[key: string]: LocaleDictionary | LocaleDictionary[] | string | object
}
export interface MessageObject {
id?: string
locale?: string