Skip to content

Commit 68f551d

Browse files
committed
update migration guide
1 parent 5a01392 commit 68f551d

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

MIGRATION.md

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ This guide will help you migrate your implementation from Optimizely JavaScript
2121
In v6, the SDK architecture has been modularized to give you more control over different components:
2222

2323
- The monolithic `createInstance` call is now split into multiple factory functions
24-
- Project configuration management is now configurable through dedicated components
25-
- Event processing has dedicated implementations for different use cases
26-
- ODP and VUID management are separate components
27-
- Logger and error handler are created through factory functions
24+
- Core functionality (project configuration, event processing, ODP, VUID, logging, and error handling) is now configured through dedicated components created via factory functions, giving you greater flexibility and control in enabling/disabling certain components and allowing optimizing the bundle size for frontend projects.
25+
- Event dispatcher interface has been updated to use Promises
26+
- onReady Promise Behavior has changed
2827

2928
## Client Initialization
3029

@@ -132,7 +131,7 @@ const projectConfigManager = createPollingProjectConfigManager({
132131

133132
### Static Project Config Manager
134133

135-
When you want to manage datafile updates manually:
134+
When you want to manage datafile updates manually or want to use a fixed datafile:
136135

137136
```javascript
138137
const projectConfigManager = createStaticProjectConfigManager({
@@ -142,16 +141,18 @@ const projectConfigManager = createStaticProjectConfigManager({
142141

143142
## Event Processing
144143

145-
v6 provides two types of event processors:
144+
In v5, a batch event processor was enabled by default. In v6, an event processor must be instantiated and passed in
145+
explicitly to `createInstance` via the `eventProcessor` option to enable event processing, otherwise no events will
146+
be dispatched. v6 provides two types of event processors:
146147

147148
### Batch Event Processor
148149

149150
Queues events and sends them in batches:
150151

151152
```javascript
152153
const batchEventProcessor = createBatchEventProcessor({
153-
batchSize: 10, // default
154-
flushInterval: 1000, // default for browser
154+
batchSize: 10, // optional, default is 10
155+
flushInterval: 1000, // optional, default 1000 for browser
155156
eventDispatcher: customEventDispatcher, // optional
156157
});
157158
```
@@ -166,9 +167,38 @@ const forwardingEventProcessor = createForwardingEventProcessor({
166167
});
167168
```
168169

170+
### Custom event dispatcher
171+
The `EventDispatcher` interface has been updated so that the `dispatchEvent` method returns a Promise instead of calling a callback.
172+
173+
In v5 (Before):
174+
175+
```javascript
176+
export type EventDispatcherResponse = {
177+
statusCode: number
178+
}
179+
180+
export type EventDispatcherCallback = (response: EventDispatcherResponse) => void
181+
182+
export interface EventDispatcher {
183+
dispatchEvent(event: EventV1Request, callback: EventDispatcherCallback): void
184+
}
185+
```
186+
187+
In v6(After):
188+
189+
```javascript
190+
export type EventDispatcherResponse = {
191+
statusCode?: number
192+
}
193+
194+
export interface EventDispatcher {
195+
dispatchEvent(event: LogEvent): Promise<EventDispatcherResponse>
196+
}
197+
```
198+
169199
## ODP Management
170200

171-
In v5, ODP functionality was configured via `odpOptions`. In v6, use the dedicated ODP Manager:
201+
In v5, ODP functionality was configured via `odpOptions` and enabled by default. In v6, instantiate an OdpManager and pass to `createInstance` to enable ODP:
172202

173203
### v5 (Before)
174204

@@ -207,7 +237,7 @@ To disable ODP functionality in v6, simply don't provide an ODP Manager to the c
207237

208238
## VUID Management
209239

210-
In v6, VUID tracking is disabled by default and must be explicitly enabled:
240+
In v6, VUID tracking is disabled by default and must be explicitly enabled by createing a vuidManager with `enableVuid` set to `true` and passing it to `createInstance`:
211241

212242
```javascript
213243
const vuidManager = createVuidManager({
@@ -220,19 +250,9 @@ const optimizely = createInstance({
220250
});
221251
```
222252

223-
To access the VUID in v6, use the VUID manager directly:
224-
225-
```javascript
226-
// v5
227-
const vuid = optimizely.getVuid();
228-
229-
// v6
230-
const vuid = vuidManager.getVuid();
231-
```
232-
233253
## Error Handling
234254

235-
Error handling in v6 uses a new error notifier pattern:
255+
Error handling in v6 uses a new errorNotifier object:
236256

237257
### v5 (Before)
238258

@@ -263,7 +283,7 @@ const optimizely = createInstance({
263283

264284
## Logging
265285

266-
Logging in v6 uses a dedicated logger created via a factory function:
286+
Logging in v6 is disabled by defualt, and must be enabled by passing in a logger created via a factory function:
267287

268288
### v5 (Before)
269289

@@ -290,7 +310,7 @@ const optimizely = createInstance({
290310

291311
## onReady Promise Behavior
292312

293-
The `onReady()` method behavior has changed:
313+
The `onReady()` method behavior has changed in v6. In v5, onReady() fulfilled with an object that had two fields: `success` and `reason`. If the instance failed to initialize, `success` would be `false` and `reason` will contain an error message. In v6, if onReady() fulfills, that means the instance is ready to use, the fulfillment value is of unknown type and need not to be inspected. If the promise rejects, that means there was an error during initialization.
294314

295315
### v5 (Before)
296316

@@ -318,21 +338,6 @@ optimizely
318338
});
319339
```
320340

321-
## Dispose of Client
322-
323-
Both versions require proper cleanup with the `close()` method. In v6, you can also make a client disposable:
324-
325-
```javascript
326-
// Create a disposable client (v6 only)
327-
const optimizely = createInstance({
328-
projectConfigManager,
329-
disposable: true
330-
});
331-
332-
// Close the client (both v5 and v6)
333-
optimizely.close();
334-
```
335-
336341
## Migration Examples
337342

338343
### Basic Example with SDK Key

0 commit comments

Comments
 (0)