This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add RemoteConfig helpers * Fix format * Rename remoteConfig to firebase and improve readme * Remove extra line * Main README entry * Fix format issues * Bump version to 1.1.0
- Loading branch information
Showing
5 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Paack's Firebase Elm Library | ||
|
||
## Remote Config | ||
|
||
Remote Config is a parameter storage that is used by some apps to toggle features and make visual changes without needing to deploy updates. | ||
|
||
The suggested use is to send the parameters using ports and store them into `AppConfig`. | ||
|
||
Example usage: | ||
|
||
```ts | ||
import firebase from 'firebase/app'; | ||
import { getConfigValue } from '@PaackEng/frontend-elm-kit/firebase/remoteConfig'; | ||
|
||
async function sendConfigs(elmApp, firebaseAppConfig) { | ||
const firebaseApp = firebase.initializeApp(firebaseAppConfig); | ||
const remoteConfig = firebaseApp.remoteConfig(); | ||
|
||
await remoteConfig.fetchAndActivate(); | ||
|
||
// read "exampleConfig" parameter as a json object | ||
const exampleConfig = await getConfigValue( | ||
remoteConfig, | ||
'exampleConfig', | ||
'object', | ||
); | ||
|
||
elmApp.ports.fromHostToElm.send({ | ||
tag: 'RemoteConfig', | ||
data: { exampleConfig }, | ||
}); | ||
} | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { RemoteConfig, Type, Value } from './types'; | ||
|
||
export async function getConfigValue( | ||
remoteConfig: RemoteConfig, | ||
key: string, | ||
type: Type, | ||
): Promise<Value> { | ||
const remoteValue = remoteConfig.getValue(key); | ||
|
||
switch (type) { | ||
case 'string': | ||
return remoteValue.asString(); | ||
case 'number': | ||
return remoteValue.asNumber(); | ||
case 'boolean': | ||
return remoteValue.asBoolean(); | ||
case 'object': | ||
return JSON.parse(remoteValue.asString()); | ||
default: | ||
return null; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import firebase from 'firebase'; | ||
|
||
export type RemoteConfig = firebase.remoteConfig.RemoteConfig; | ||
|
||
export type Type = 'string' | 'number' | 'boolean' | 'object'; | ||
|
||
export type Value = string | number | boolean | null; |
This file contains 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