From 791ef4d4234b232f35983a3909dfb320f935890a Mon Sep 17 00:00:00 2001 From: Gleidson Daniel Silva Date: Tue, 11 Jan 2022 11:23:43 -0300 Subject: [PATCH] Chore: Migrate lib user preferences to Typescript (#3578) --- .../{userPreferences.js => userPreferences.ts} | 15 ++++++++------- app/views/DefaultBrowserView.tsx | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) rename app/lib/{userPreferences.js => userPreferences.ts} (75%) diff --git a/app/lib/userPreferences.js b/app/lib/userPreferences.ts similarity index 75% rename from app/lib/userPreferences.js rename to app/lib/userPreferences.ts index 3377856d6..6f4818da6 100644 --- a/app/lib/userPreferences.js +++ b/app/lib/userPreferences.ts @@ -7,11 +7,12 @@ const MMKV = new MMKVStorage.Loader() .initialize(); class UserPreferences { + private mmkv: MMKVStorage.API; constructor() { this.mmkv = MMKV; } - async getStringAsync(key) { + async getStringAsync(key: string) { try { const value = await this.mmkv.getStringAsync(key); return value; @@ -20,11 +21,11 @@ class UserPreferences { } } - setStringAsync(key, value) { + setStringAsync(key: string, value: string) { return this.mmkv.setStringAsync(key, value); } - async getBoolAsync(key) { + async getBoolAsync(key: string) { try { const value = await this.mmkv.getBoolAsync(key); return value; @@ -33,11 +34,11 @@ class UserPreferences { } } - setBoolAsync(key, value) { + setBoolAsync(key: string, value: boolean) { return this.mmkv.setBoolAsync(key, value); } - async getMapAsync(key) { + async getMapAsync(key: string) { try { const value = await this.mmkv.getMapAsync(key); return value; @@ -46,11 +47,11 @@ class UserPreferences { } } - setMapAsync(key, value) { + setMapAsync(key: string, value: object) { return this.mmkv.setMapAsync(key, value); } - removeItem(key) { + removeItem(key: string) { return this.mmkv.removeItem(key); } } diff --git a/app/views/DefaultBrowserView.tsx b/app/views/DefaultBrowserView.tsx index 0282e0df2..cfe977d2c 100644 --- a/app/views/DefaultBrowserView.tsx +++ b/app/views/DefaultBrowserView.tsx @@ -107,7 +107,7 @@ class DefaultBrowserView extends React.Component { logEvent(events.DB_CHANGE_DEFAULT_BROWSER, { browser: newBrowser }); try { - const browser = newBrowser !== 'systemDefault:' ? newBrowser : null; + const browser = newBrowser || 'systemDefault:'; await UserPreferences.setStringAsync(DEFAULT_BROWSER_KEY, browser); this.setState({ browser }); } catch {