forked from launchdarkly/hello-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
58 lines (51 loc) · 1.94 KB
/
index.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1">
<title>LaunchDarkly tutorial</title>
<script src="https://unpkg.com/launchdarkly-js-client-sdk@3"></script>
<link rel="stylesheet" href="./index.css">
</head>
<body>
<script>
function main()
{
// Set clientSideID to your LaunchDarkly client-side ID
const clientSideID = '';
// Set flagKey to the feature flag key you want to evaluate
const flagKey = 'sample-feature';
// Set up the evaluation context. This context should appear on your
// LaunchDarkly contexts dashboard soon after you run the demo.
const context = {
kind: 'user',
key: 'example-user-key',
name: 'Sandy'
};
var div = document.createElement('div');
document.body.appendChild(div);
div.appendChild(document.createTextNode('Initializing...'));
if (clientSideID === '') {
div.replaceChild(document.createTextNode('Please edit index.html to set clientSideID to your LaunchDarkly client-side ID first'), div.firstChild);
return;
}
const ldclient = LDClient.initialize(clientSideID, context);
function render() {
const flagValue = ldclient.variation(flagKey, false);
const label = `The ${flagKey} feature flag evaluates to ${flagValue}.`;
document.body.style.background = flagValue ? '#00844B' : '#373841';
div.replaceChild(document.createTextNode(label), div.firstChild);
}
ldclient.on('initialized', () => {
div.replaceChild(document.createTextNode('SDK successfully initialized!'), div.firstChild);
});
ldclient.on('failed', () => {
div.replaceChild(document.createTextNode('SDK failed to initialize'), div.firstChild);
});
ldclient.on('ready', render);
ldclient.on('change', render);
}
main();
</script>
</body>
</html>