@@ -3,26 +3,28 @@ import { forOwn } from '../../utils/lang';
33import { IReadinessManager } from '../../readiness/types' ;
44import { IStorageSync } from '../../storages/types' ;
55import { mySegmentsSyncTaskFactory } from './syncTasks/mySegmentsSyncTask' ;
6- import { splitsSyncTaskFactory } from './syncTasks/splitsSyncTask ' ;
6+ import { definitionsSyncTaskFactory } from './syncTasks/definitionsSyncTask ' ;
77import { getMatching } from '../../utils/key' ;
88import { SDK_SPLITS_ARRIVED , SDK_SEGMENTS_ARRIVED } from '../../readiness/constants' ;
99import { POLLING_SMART_PAUSING , POLLING_START , POLLING_STOP } from '../../logger/constants' ;
1010import { ISdkFactoryContextSync } from '../../sdkFactory/types' ;
1111import { usesSegmentsSync } from '../../storages/AbstractSplitsCacheSync' ;
1212import { SdkUpdateMetadata } from '../../../types/splitio' ;
13+ import { IDefinitionChangesFetcher } from './fetchers/types' ;
1314
1415/**
1516 * Expose start / stop mechanism for polling data from services.
1617 * For client-side API with multiple clients.
1718 */
1819export function pollingManagerCSFactory (
19- params : ISdkFactoryContextSync
20+ params : ISdkFactoryContextSync ,
21+ definitionChangesFetcher : IDefinitionChangesFetcher
2022) : IPollingManagerCS {
2123
2224 const { splitApi, storage, readiness, settings } = params ;
2325 const log = settings . log ;
2426
25- const splitsSyncTask = splitsSyncTaskFactory ( splitApi . fetchSplitChanges , storage , readiness , settings , true ) ;
27+ const definitionsSyncTask = definitionsSyncTaskFactory ( definitionChangesFetcher , storage , readiness , settings , true ) ;
2628
2729 // Map of matching keys to their corresponding MySegmentsSyncTask.
2830 const mySegmentsSyncTasks : Record < string , IMySegmentsSyncTask > = { } ;
@@ -44,7 +46,7 @@ export function pollingManagerCSFactory(
4446
4547 // smart pausing
4648 readiness . splits . on ( SDK_SPLITS_ARRIVED , ( ) => {
47- if ( ! splitsSyncTask . isRunning ( ) ) return ; // noop if not doing polling
49+ if ( ! definitionsSyncTask . isRunning ( ) ) return ; // noop if not doing polling
4850 const usingSegments = usesSegmentsSync ( storage ) ;
4951 if ( usingSegments !== mySegmentsSyncTask . isRunning ( ) ) {
5052 log . info ( POLLING_SMART_PAUSING , [ usingSegments ? 'ON' : 'OFF' ] ) ;
@@ -71,31 +73,31 @@ export function pollingManagerCSFactory(
7173 }
7274
7375 return {
74- splitsSyncTask ,
76+ definitionsSyncTask ,
7577 segmentsSyncTask : mySegmentsSyncTask ,
7678
7779 // Start periodic fetching (polling)
7880 start ( ) {
7981 log . info ( POLLING_START ) ;
8082
81- splitsSyncTask . start ( ) ;
83+ definitionsSyncTask . start ( ) ;
8284 if ( usesSegmentsSync ( storage ) ) startMySegmentsSyncTasks ( ) ;
8385 } ,
8486
8587 // Stop periodic fetching (polling)
8688 stop ( ) {
8789 log . info ( POLLING_STOP ) ;
8890
89- if ( splitsSyncTask . isRunning ( ) ) splitsSyncTask . stop ( ) ;
91+ if ( definitionsSyncTask . isRunning ( ) ) definitionsSyncTask . stop ( ) ;
9092 stopMySegmentsSyncTasks ( ) ;
9193 } ,
9294
9395 // Used by SyncManager to know if running in polling mode.
94- isRunning : splitsSyncTask . isRunning ,
96+ isRunning : definitionsSyncTask . isRunning ,
9597
96- // fetch splits and segments
98+ // fetch definitions and segments
9799 syncAll ( ) {
98- const promises = [ splitsSyncTask . execute ( ) ] ;
100+ const promises = [ definitionsSyncTask . execute ( ) ] ;
99101 forOwn ( mySegmentsSyncTasks , ( mySegmentsSyncTask ) => {
100102 promises . push ( mySegmentsSyncTask . execute ( ) ) ;
101103 } ) ;
0 commit comments