Skip to content

Commit f4ad1e7

Browse files
committed
chore: addressing cursor comments
1 parent 31e0dd9 commit f4ad1e7

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

packages/sdk/browser/example/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@launchdarkly/browser-example",
33
"version": "0.0.0",
4-
"prviate": true,
4+
"private": true,
55
"description": "LaunchDarkly example for JavaScript Browser SDK",
66
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/browser/example",
77
"repository": {
@@ -17,8 +17,7 @@
1717
"build": "npm run clean && tsdown"
1818
},
1919
"dependencies": {
20-
"@launchdarkly/js-client-sdk": "workspace:^",
21-
"express": "^5.1.0"
20+
"@launchdarkly/js-client-sdk": "workspace:^"
2221
},
2322
"devDependencies": {
2423
"tsdown": "^0.17.0-beta.4",

packages/sdk/browser/example/src/app.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,30 @@ const context = {
1717
const div = document.createElement('div');
1818
document.body.appendChild(div);
1919
div.appendChild(document.createTextNode('Initializing...'));
20+
try {
21+
const ldclient = initialize(clientSideID);
22+
const render = () => {
23+
const flagValue = ldclient.variation(flagKey, false);
24+
const label = `The ${flagKey} feature flag evaluates to ${flagValue}.`;
25+
document.body.style.background = flagValue ? '#00844B' : '#373841';
26+
div.replaceChild(document.createTextNode(label), div.firstChild as Node);
27+
};
2028

21-
const ldclient = initialize(clientSideID);
22-
23-
function render() {
24-
const flagValue = ldclient.variation(flagKey, false);
25-
const label = `The ${flagKey} feature flag evaluates to ${flagValue}.`;
26-
document.body.style.background = flagValue ? '#00844B' : '#373841';
27-
div.replaceChild(document.createTextNode(label), div.firstChild as Node);
28-
}
29+
ldclient.on('error', () => {
30+
div.replaceChild(document.createTextNode('Error caught in client SDK'), div.firstChild as Node);
31+
});
2932

30-
ldclient.identify(context).then(() => {
31-
ldclient.on('initialized', () => {
32-
div.replaceChild(
33-
document.createTextNode('SDK successfully initialized!'),
34-
div.firstChild as Node,
35-
);
33+
ldclient.on('change', () => {
34+
render();
3635
});
37-
ldclient.on('failed', () => {
38-
div.replaceChild(document.createTextNode('SDK failed to initialize'), div.firstChild as Node);
36+
37+
ldclient.identify(context).catch(() => {
38+
div.replaceChild(document.createTextNode('Error identifying client'), div.firstChild as Node);
3939
});
40-
ldclient.on('ready', render);
41-
ldclient.on('change', render);
42-
});
40+
} catch (error) {
41+
div.replaceChild(
42+
document.createTextNode(`Error initializing LaunchDarkly client: ${error}`),
43+
div.firstChild as Node,
44+
);
45+
document.body.style.background = '#373841';
46+
}

0 commit comments

Comments
 (0)