fix(state): sync locale correctly

This commit is contained in:
Paul Makles 2022-01-15 15:43:32 +00:00
parent 3ce04f543f
commit 05266790ae

View file

@ -4,6 +4,7 @@ import { Language, Languages } from "../../context/Locale";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
import Syncable from "../interfaces/Syncable";
export interface Data {
lang: Language;
@ -51,7 +52,9 @@ export function findLanguage(lang?: string): Language {
/**
* Keeps track of user's language settings.
*/
export default class LocaleOptions implements Store, Persistent<Data> {
export default class LocaleOptions
implements Store, Persistent<Data>, Syncable
{
private lang: Language;
/**
@ -72,6 +75,16 @@ export default class LocaleOptions implements Store, Persistent<Data> {
};
}
apply(_key: "locale", data: unknown, _revision: number): void {
this.hydrate(data as Data);
}
@computed toSyncable(): { [key: string]: object } {
return {
locale: this.toJSON(),
};
}
@action hydrate(data: Data) {
this.setLanguage(data.lang);
}