-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathRemoteConfig.svelte
More file actions
39 lines (30 loc) · 1.19 KB
/
RemoteConfig.svelte
File metadata and controls
39 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script lang="ts">
import { getFirebaseContext } from '$lib/stores/sdk.js';
import type { RemoteConfig } from 'firebase/remote-config';
import { getRemoteConfig } from 'firebase/remote-config';
import { remoteConfigActivationStore } from '$lib/stores/remote-config.js';
import { onMount } from 'svelte';
export let defaultValue = {};
export let minimumFetchIntervalMillis = 3600000;
let configActivated;
let remoteConfig: RemoteConfig | undefined;
const { app } = getFirebaseContext();
// Initialize remote config instance with default values and minimum fetch interval
// The instance will be created when the component is mounted because Remote Config
// requires the code to run in the browser
onMount(() => {
remoteConfig = getRemoteConfig(app);
remoteConfig.settings.minimumFetchIntervalMillis = minimumFetchIntervalMillis;
remoteConfig.defaultConfig = defaultValue;
configActivated = remoteConfigActivationStore(remoteConfig);
});
interface $$Slots {
default: { remoteConfig?: RemoteConfig },
loading: {},
}
</script>
{#if remoteConfig !== undefined && $configActivated === true}
<slot {remoteConfig} />
{:else}
<slot name="loading" />
{/if}