Skip to content

Commit 114b5be

Browse files
authored
Remote Config Snippets (firebase#68)
1 parent da6a238 commit 114b5be

File tree

10 files changed

+183
-1
lines changed

10 files changed

+183
-1
lines changed

lerna.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"functions-next",
1111
"installations",
1212
"perf",
13-
"perf-next"
13+
"perf-next",
14+
"remoteconfig",
15+
"remoteconfig-next"
1416
],
1517
"version": "1.0.0"
1618
}

remoteconfig-next/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// [SNIPPETS_REGISTRY disabled]
2+
// [SNIPPETS_SEPARATION enabled]
3+
4+
import { initializeApp } from "firebase/app";
5+
6+
const firebaseApp = initializeApp({
7+
apiKey: '### FIREBASE API KEY ###',
8+
appId: '### FIREBASE APP ID ###',
9+
projectId: '### FIREBASE PROJECT ID ###'
10+
});
11+
12+
function getInstance() {
13+
// [START rc_get_instance]
14+
const { getRemoteConfig } = require("firebase/remote-config");
15+
16+
const remoteConfig = getRemoteConfig(firebaseApp);
17+
// [END rc_get_instance]
18+
19+
return remoteConfig;
20+
}
21+
22+
function setMinimumFetchTime() {
23+
const remoteConfig = getInstance();
24+
// [START rc_set_minimum_fetch_time]
25+
remoteConfig.settings.minimumFetchIntervalMillis = 3600000;
26+
// [END rc_set_minimum_fetch_time]
27+
}
28+
29+
function setDefaultValues() {
30+
const remoteConfig = getInstance();
31+
// [START rc_set_default_values]
32+
remoteConfig.defaultConfig = {
33+
"welcome_message": "Welcome"
34+
};
35+
// [END rc_set_default_values]
36+
}
37+
38+
function getValues() {
39+
const remoteConfig = getInstance();
40+
// [START rc_get_values]
41+
const { getValue } = require("firebase/remote-config");
42+
43+
const val = getValue(remoteConfig, "welcome_messsage");
44+
// [END rc_get_values]
45+
}
46+
47+
function fetchConfigCallback() {
48+
const remoteConfig = getInstance();
49+
// [START rc_fetch_config_callback]
50+
const { fetchAndActivate } = require("firebase/remote-config");
51+
52+
fetchAndActivate(remoteConfig)
53+
.then(() => {
54+
// ...
55+
})
56+
.catch((err) => {
57+
// ...
58+
});
59+
// [END rc_fetch_config_callback]
60+
}

remoteconfig-next/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "remoteconfig-next",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6+
},
7+
"license": "Apache-2.0",
8+
"dependencies": {
9+
"firebase": "exp"
10+
}
11+
}

remoteconfig/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import firebase from "firebase";
2+
import "firebase/remote-config";
3+
4+
function getInstance() {
5+
// [START rc_get_instance]
6+
const remoteConfig = firebase.remoteConfig();
7+
// [END rc_get_instance]
8+
}
9+
10+
function setMinimumFetchTime() {
11+
const remoteConfig = firebase.remoteConfig();
12+
// [START rc_set_minimum_fetch_time]
13+
remoteConfig.settings.minimumFetchIntervalMillis = 3600000;
14+
// [END rc_set_minimum_fetch_time]
15+
}
16+
17+
function setDefaultValues() {
18+
const remoteConfig = firebase.remoteConfig();
19+
// [START rc_set_default_values]
20+
remoteConfig.defaultConfig = {
21+
"welcome_message": "Welcome"
22+
};
23+
// [END rc_set_default_values]
24+
}
25+
26+
function getValues() {
27+
const remoteConfig = firebase.remoteConfig();
28+
// [START rc_get_values]
29+
const val = remoteConfig.getValue("welcome_messsage");
30+
// [END rc_get_values]
31+
}
32+
33+
function fetchConfigCallback() {
34+
const remoteConfig = firebase.remoteConfig();
35+
// [START rc_fetch_config_callback]
36+
remoteConfig.fetchAndActivate()
37+
.then(() => {
38+
// ...
39+
})
40+
.catch((err) => {
41+
// ...
42+
});
43+
// [END rc_fetch_config_callback]
44+
}

remoteconfig/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "remoteconfig",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc"
6+
},
7+
"license": "Apache-2.0",
8+
"dependencies": {
9+
"firebase": "^8.1.2"
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./remoteconfig-next/index.js
3+
//
4+
// To make edits to the snippets in this file, please edit the source
5+
6+
// [START rc_fetch_config_callback_modular]
7+
import { fetchAndActivate } from "firebase/remote-config";
8+
9+
fetchAndActivate(remoteConfig)
10+
.then(() => {
11+
// ...
12+
})
13+
.catch((err) => {
14+
// ...
15+
});
16+
// [END rc_fetch_config_callback_modular]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./remoteconfig-next/index.js
3+
//
4+
// To make edits to the snippets in this file, please edit the source
5+
6+
// [START rc_get_instance_modular]
7+
import { getRemoteConfig } from "firebase/remote-config";
8+
9+
const remoteConfig = getRemoteConfig(firebaseApp);
10+
// [END rc_get_instance_modular]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./remoteconfig-next/index.js
3+
//
4+
// To make edits to the snippets in this file, please edit the source
5+
6+
// [START rc_get_values_modular]
7+
import { getValue } from "firebase/remote-config";
8+
9+
const val = getValue(remoteConfig, "welcome_messsage");
10+
// [END rc_get_values_modular]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./remoteconfig-next/index.js
3+
//
4+
// To make edits to the snippets in this file, please edit the source
5+
6+
// [START rc_set_default_values_modular]
7+
remoteConfig.defaultConfig = {
8+
"welcome_message": "Welcome"
9+
};
10+
// [END rc_set_default_values_modular]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./remoteconfig-next/index.js
3+
//
4+
// To make edits to the snippets in this file, please edit the source
5+
6+
// [START rc_set_minimum_fetch_time_modular]
7+
remoteConfig.settings.minimumFetchIntervalMillis = 3600000;
8+
// [END rc_set_minimum_fetch_time_modular]

0 commit comments

Comments
 (0)