1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Files
tooot/src/utils/helpers/checkEnvironment.ts
xmflsct 1ea6aff328 619 restructure local storage (#628)
* To MMKV migration working

* POC migrated font size settings

* Moved settings to mmkv

* Fix typos

* Migrated contexts slice

* Migrated app slice

* POC instance emoji update

* Migrated drafts

* Migrated simple instance properties

* All migrated!

* Re-structure files

* Tolerant of undefined settings

* Can properly logging in and out including empty state
2022-12-28 23:41:36 +01:00

50 lines
1.0 KiB
TypeScript

import Constants from 'expo-constants'
const mapEnvironment = <T = unknown>({
release,
candidate,
development
}: {
release: T
candidate?: T
development?: T
}): T => {
if (isDevelopment) {
if (development) {
return development
} else {
throw new Error('Development environment but no development handler')
}
}
if (isCandidate) {
if (candidate) {
return candidate
} else {
throw new Error('Candidate environment but no candidate handler')
}
}
if (isRelease) {
return release
}
throw new Error(
`Environment not set. Please set the environment in the Expo project settings.`
)
}
const isDevelopment =
__DEV__ ||
['development'].some(channel => (Constants.expoConfig?.extra?.environment) === channel)
const isCandidate = ['candidate'].some(channel =>
(Constants.expoConfig?.extra?.environment) === channel
)
const isRelease = ['release'].some(channel =>
(Constants.expoConfig?.extra?.environment) === channel
)
export { mapEnvironment, isDevelopment, isCandidate, isRelease }