-
Notifications
You must be signed in to change notification settings - Fork 31
chore: update svelte sdk to use browser 4.x #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| import { derived, type Readable, readonly, writable, type Writable } from 'svelte/store'; | ||
|
|
||
| import type { LDFlagSet } from '@launchdarkly/js-client-sdk'; | ||
| import { | ||
| initialize, | ||
| createClient as createClientSdk, | ||
| type LDClient, | ||
| type LDContext, | ||
| type LDFlagSet, | ||
| type LDFlagValue, | ||
| } from '@launchdarkly/js-client-sdk/compat'; | ||
| type LDOptions, | ||
| } from '@launchdarkly/js-client-sdk'; | ||
|
|
||
| export type { LDContext, LDFlagValue }; | ||
|
|
||
|
|
@@ -62,7 +63,7 @@ function toFlagsProxy(client: LDClient, flags: LDFlags): LDFlags { | |
| * Creates a LaunchDarkly instance. | ||
| * @returns {Object} The LaunchDarkly instance object. | ||
| */ | ||
| function createLD() { | ||
| function init() { | ||
| let coreLdClient: LDClient | undefined; | ||
| const loading = writable(true); | ||
| const flagsWritable = writable<LDFlags>({}); | ||
|
|
@@ -73,21 +74,23 @@ function createLD() { | |
| * @param {LDContext} context - The user context. | ||
| * @returns {Object} An object with the initialization status store. | ||
| */ | ||
| function LDInitialize(clientId: LDClientID, context: LDContext) { | ||
| coreLdClient = initialize(clientId, context); | ||
| coreLdClient!.on('ready', () => { | ||
| function initialize(clientId: LDClientID, context: LDContext, options?: LDOptions) { | ||
| coreLdClient = createClientSdk(clientId, context, options); | ||
| coreLdClient.on('initialized', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Initialization failure leaves loading state stuck foreverThe migration from the compat SDK's |
||
| loading.set(false); | ||
| const rawFlags = coreLdClient!.allFlags(); | ||
| const allFlags = toFlagsProxy(coreLdClient!, rawFlags); | ||
| flagsWritable.set(allFlags); | ||
| }); | ||
|
|
||
| coreLdClient!.on('change', () => { | ||
| coreLdClient.on('change', () => { | ||
| const rawFlags = coreLdClient!.allFlags(); | ||
| const allFlags = toFlagsProxy(coreLdClient!, rawFlags); | ||
| flagsWritable.set(allFlags); | ||
| }); | ||
|
|
||
| coreLdClient.start(); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: identify method return type changed breaking existing codeThe migration changes the return type of the |
||
| return { | ||
| initializing: loading, | ||
| }; | ||
|
|
@@ -125,12 +128,12 @@ function createLD() { | |
| return { | ||
| identify, | ||
| flags: readonly(flagsWritable), | ||
| initialize: LDInitialize, | ||
| initialize, | ||
| initializing: readonly(loading), | ||
| watch, | ||
| useFlag, | ||
| }; | ||
| } | ||
|
|
||
| /** The LaunchDarkly instance */ | ||
| export const LD = createLD(); | ||
| export const LD = init(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Test emits wrong event after API migration
The migration from the compat API to browser 4.x changed the initialization event from
'ready'to'initialized', but one test case was missed. Line 134 still emitsmockLDEventEmitter.emit('ready')while the implementation now listens for'initialized'. This causes the test to not properly trigger the initialization callback, though it may pass coincidentally due to state leaking from other tests that correctly emit'initialized'.