Last active
December 18, 2020 23:48
-
-
Save sudomann/788cd26c4a592b6e764d4d0e42a56a3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class ChoiceSetting { | |
static storageKey = undefined; | |
static label = undefined; | |
static defaultValue = undefined; | |
static set defaultValue(value) { | |
if (failsValidation(value)) | |
throw new Error(); | |
this.defaultValue = value; | |
} | |
static getValueAsync = async () => { | |
if (!(this.storageKey && this.label && this.defaultValue)) | |
throw new Error(); | |
return SecureStore.getItemAsync(this.storageKey).catch(() => this.defaultValue); | |
}; | |
static setValueAsync = async (value) => { | |
if (failsValidation(value)) | |
throw new Error(); | |
return SecureStore.setItemAsync(this.storageKey, value); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class SettingsStore { | |
/** | |
* | |
* @param {string} userId UUID of currently signed in user | |
*/ | |
constructor(userId) { | |
this.useBiometricFace = new BooleanSetting( | |
"useBiometricFace", | |
userId, | |
BooleanSetting.States.OFF | |
); | |
this.useBiometricFinger = new BooleanSetting( | |
"useBiometricFinger", | |
userId, | |
BooleanSetting.States.OFF | |
); | |
this.useSound = new BooleanSetting( | |
"useSound", | |
userId, | |
BooleanSetting.States.ON | |
); | |
} | |
static appLanguage = class extends ChoiceSetting { | |
static label = "appLanguage"; | |
static CHOICES = Object.freeze({ | |
en: "en_US", | |
fr: "fr_FR", | |
}); | |
}; | |
static appTheme = class extends ChoiceSetting { | |
static label = "appTheme"; | |
static CHOICES = Object.freeze({ | |
DEFAULT: "default", // light | |
DARK: "dark", | |
SYSTEM: "system", | |
}); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ChoiceSetting from './choice-setting' | |
export default class SettingsStore { | |
/** | |
* | |
* @param {string} userId UUID of currently signed in user | |
*/ | |
constructor(userId) { | |
//... some setup | |
} | |
static appLanguage = class extends ChoiceSetting { | |
static label = "appLanguage"; | |
static CHOICES = Object.freeze({ | |
en: "en_US", | |
fr: "fr_FR", | |
}); | |
}; | |
static appTheme = class extends ChoiceSetting { | |
static label = "appTheme"; | |
static CHOICES = Object.freeze({ | |
DEFAULT: "default", // light | |
DARK: "dark", | |
SYSTEM: "system", | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment