Chore: Migrate lib user preferences to Typescript (#3578)

This commit is contained in:
Gleidson Daniel Silva 2022-01-11 11:23:43 -03:00 committed by GitHub
parent 13af9d80ed
commit 791ef4d423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -7,11 +7,12 @@ const MMKV = new MMKVStorage.Loader()
.initialize(); .initialize();
class UserPreferences { class UserPreferences {
private mmkv: MMKVStorage.API;
constructor() { constructor() {
this.mmkv = MMKV; this.mmkv = MMKV;
} }
async getStringAsync(key) { async getStringAsync(key: string) {
try { try {
const value = await this.mmkv.getStringAsync(key); const value = await this.mmkv.getStringAsync(key);
return value; return value;
@ -20,11 +21,11 @@ class UserPreferences {
} }
} }
setStringAsync(key, value) { setStringAsync(key: string, value: string) {
return this.mmkv.setStringAsync(key, value); return this.mmkv.setStringAsync(key, value);
} }
async getBoolAsync(key) { async getBoolAsync(key: string) {
try { try {
const value = await this.mmkv.getBoolAsync(key); const value = await this.mmkv.getBoolAsync(key);
return value; return value;
@ -33,11 +34,11 @@ class UserPreferences {
} }
} }
setBoolAsync(key, value) { setBoolAsync(key: string, value: boolean) {
return this.mmkv.setBoolAsync(key, value); return this.mmkv.setBoolAsync(key, value);
} }
async getMapAsync(key) { async getMapAsync(key: string) {
try { try {
const value = await this.mmkv.getMapAsync(key); const value = await this.mmkv.getMapAsync(key);
return value; return value;
@ -46,11 +47,11 @@ class UserPreferences {
} }
} }
setMapAsync(key, value) { setMapAsync(key: string, value: object) {
return this.mmkv.setMapAsync(key, value); return this.mmkv.setMapAsync(key, value);
} }
removeItem(key) { removeItem(key: string) {
return this.mmkv.removeItem(key); return this.mmkv.removeItem(key);
} }
} }

View File

@ -107,7 +107,7 @@ class DefaultBrowserView extends React.Component<IDefaultBrowserViewProps, IDefa
changeDefaultBrowser = async (newBrowser: TValue) => { changeDefaultBrowser = async (newBrowser: TValue) => {
logEvent(events.DB_CHANGE_DEFAULT_BROWSER, { browser: newBrowser }); logEvent(events.DB_CHANGE_DEFAULT_BROWSER, { browser: newBrowser });
try { try {
const browser = newBrowser !== 'systemDefault:' ? newBrowser : null; const browser = newBrowser || 'systemDefault:';
await UserPreferences.setStringAsync(DEFAULT_BROWSER_KEY, browser); await UserPreferences.setStringAsync(DEFAULT_BROWSER_KEY, browser);
this.setState({ browser }); this.setState({ browser });
} catch { } catch {