-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathldclient-lazy.tsx
More file actions
126 lines (116 loc) · 2.5 KB
/
ldclient-lazy.tsx
File metadata and controls
126 lines (116 loc) · 2.5 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { LDObserve } from '@launchdarkly/observability'
import { LDRecord } from '@launchdarkly/session-replay'
import { useState } from 'react'
import { client, recordObservability, recordSession } from '../ldclientLazy'
export default function LDClientLazyPage() {
const [flags, setFlags] = useState<string>()
const [session, setSession] = useState<string>()
const [started, setStarted] = useState(false)
return (
<div id="ldclient-lazy-page">
<h1>LDClient Lazy (Manual Start)</h1>
<p>
Uses <code>ldclientLazy.tsx</code> — plugins have{' '}
<code>manualStart: true</code> and must be started explicitly.
</p>
<nav style={{ marginBottom: 16 }}>
<a href="/">← Home</a>
</nav>
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 8,
maxWidth: 400,
}}
>
<button
onClick={async () => {
await recordObservability()
await recordSession()
setStarted(true)
}}
>
Start plugins (recordObservability + recordSession)
</button>
{started && <p style={{ color: 'green' }}>Plugins started</p>}
<button
onClick={() => {
const url = LDRecord.getSession()?.url
setSession(url)
}}
>
Get session URL
</button>
{session && (
<a href={session} target="_blank" rel="noreferrer">
{session}
</a>
)}
<button
onClick={() => {
LDObserve.recordLog(
'hello from ldclient-lazy page',
'info',
)
}}
>
LDObserve.recordLog
</button>
<button
onClick={() => {
LDObserve.recordError(
new Error('test error from ldclient-lazy page'),
)
}}
>
LDObserve.recordError
</button>
<button
onClick={async () => {
await client.identify({
kind: 'user',
key: 'ldclient-lazy-test-user',
})
setFlags(JSON.stringify(client.allFlags(), null, 2))
}}
>
client.identify
</button>
<button
onClick={() => {
setFlags(
JSON.stringify(
client.variation('enable-session-card-style'),
null,
2,
),
)
}}
>
client.variation
</button>
<button
onClick={() => {
client.track('ldclient-lazy-page-custom-event', {
random: Math.random(),
})
}}
>
client.track
</button>
{flags && (
<pre
style={{
background: '#f5f5f5',
padding: 8,
borderRadius: 4,
}}
>
{flags}
</pre>
)}
</div>
</div>
)
}