Skip to content

Commit a21b098

Browse files
Merge branch 'SDKS-8407_baseline' into refactor_storage_emits_ready_from_cache
2 parents c270290 + 411ce8f commit a21b098

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- Added support for targeting rules based on large segments.
33
- Added `factory.destroy()` method, which invokes the `destroy` method on all SDK clients created by the factory.
44
- Updated internal storage factory to emit the SDK_READY_FROM_CACHE event when it corresponds, to clean up the initialization flow.
5-
- Updated the handling of timers and async operations by moving them into an `init` factory method to enable lazy initialization of the SDK. This update is intended for the React SDK.
5+
- Updated the handling of timers and async operations inside an `init` factory method to enable lazy initialization of the SDK. This update is intended for the React SDK.
66
- Bugfixing - Fixed an issue with the server-side polling manager that caused dangling timers when the SDK was destroyed before it was ready.
77
- BREAKING CHANGES:
88
- Updated default flag spec version to 1.2.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-commons",
3-
"version": "1.17.1-rc.3",
3+
"version": "1.17.1-rc.4",
44
"description": "Split JavaScript SDK common components",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",

src/sync/offline/syncManagerOffline.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ISyncManager, ISyncManagerCS } from '../types';
1+
import { ISyncManagerCS } from '../types';
22
import { fromObjectSyncTaskFactory } from './syncTasks/fromObjectSyncTask';
33
import { objectAssign } from '../../utils/lang/objectAssign';
44
import { ISplitsParser } from './splitsParser/types';
@@ -29,26 +29,34 @@ export function syncManagerOfflineFactory(
2929
storage,
3030
}: ISdkFactoryContextSync): ISyncManagerCS {
3131

32+
const mainSyncManager = fromObjectSyncTaskFactory(splitsParserFactory(), storage, readiness, settings);
33+
const mainStart = mainSyncManager.start;
34+
const sharedStarts: Array<() => void> = [];
35+
3236
return objectAssign(
33-
fromObjectSyncTaskFactory(splitsParserFactory(), storage, readiness, settings),
37+
mainSyncManager,
3438
{
39+
start() {
40+
mainStart();
41+
sharedStarts.forEach(cb => cb());
42+
sharedStarts.length = 0;
43+
},
3544
// fake flush, that resolves immediately
3645
flush,
3746

3847
// [Only used for client-side]
39-
shared(matchingKey: string, readinessManager: IReadinessManager): ISyncManager {
48+
shared(matchingKey: string, readinessManager: IReadinessManager) {
49+
// In LOCALHOST mode, shared clients are ready in the next event-loop cycle than created
50+
// SDK_READY cannot be emitted directly because this will not update the readiness status
51+
function emitSdkReady() {
52+
readinessManager.segments.emit(SDK_SEGMENTS_ARRIVED); // SDK_SPLITS_ARRIVED emitted by main SyncManager
53+
}
54+
55+
if (mainSyncManager.isRunning()) setTimeout(emitSdkReady);
56+
else sharedStarts.push(emitSdkReady);
57+
4058
return {
41-
start() {
42-
// In LOCALHOST mode, shared clients are ready in the next event-loop cycle than created
43-
// SDK_READY cannot be emitted directly because this will not update the readiness status
44-
setTimeout(() => {
45-
readinessManager.segments.emit(SDK_SEGMENTS_ARRIVED); // SDK_SPLITS_ARRIVED emitted by main SyncManager
46-
}, 0);
47-
},
4859
stop() { },
49-
isRunning() {
50-
return true;
51-
},
5260
flush,
5361
};
5462
}

src/sync/syncManagerOnline.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ export function syncManagerOnlineFactory(
164164
}
165165

166166
return {
167-
isRunning: mySegmentsSyncTask.isRunning,
168-
169167
stop() {
170168
// check in case `client.destroy()` has been invoked more than once for the same client
171169
const mySegmentsSyncTask = (pollingManager as IPollingManagerCS).get(matchingKey);

0 commit comments

Comments
 (0)