@@ -59,7 +59,6 @@ export class Replane<T extends object = Record<string, unknown>> {
5959 private logger : ReplaneLogger ;
6060 private storage : ReplaneRemoteStorage | null = null ;
6161 private configSubscriptions = new Map < keyof T , Set < ( config : MapConfig < T > ) => void > > ( ) ;
62- private clientSubscriptions = new Set < ( config : MapConfig < T > ) => void > ( ) ;
6362
6463 /**
6564 * Create a new Replane client.
@@ -215,24 +214,6 @@ export class Replane<T extends object = Record<string, unknown>> {
215214 }
216215 }
217216
218- /**
219- * Subscribe to config changes.
220- *
221- * @param callback - Function called when any config changes
222- * @returns Unsubscribe function
223- *
224- * @example
225- * ```typescript
226- * const unsubscribe = client.subscribe((change) => {
227- * console.log(`Config ${change.name} changed to ${change.value}`);
228- * });
229- *
230- * // Later: stop listening
231- * unsubscribe();
232- * ```
233- */
234- subscribe ( callback : ( config : MapConfig < T > ) => void ) : ( ) => void ;
235-
236217 /**
237218 * Subscribe to a specific config's changes.
238219 *
@@ -250,46 +231,20 @@ export class Replane<T extends object = Record<string, unknown>> {
250231 subscribe < K extends keyof T > (
251232 configName : K ,
252233 callback : ( config : { name : K ; value : T [ K ] } ) => void
253- ) : ( ) => void ;
254-
255- subscribe < K extends keyof T > (
256- callbackOrConfigName : K | ( ( config : MapConfig < T > ) => void ) ,
257- callbackOrUndefined ?: ( config : { name : K ; value : T [ K ] } ) => void
258234 ) : ( ) => void {
259- let configName : keyof T | undefined = undefined ;
260- let callback : ( config : MapConfig < T > ) => void ;
261-
262- if ( typeof callbackOrConfigName === "function" ) {
263- callback = callbackOrConfigName ;
264- } else {
265- configName = callbackOrConfigName as keyof T ;
266- if ( callbackOrUndefined === undefined ) {
267- throw new Error ( "callback is required when config name is provided" ) ;
268- }
269- // Type assertion is safe: MapConfig<T> is a union that includes { name: K, value: T[K] }
270- callback = callbackOrUndefined as ( config : MapConfig < T > ) => void ;
271- }
272-
273235 // Wrap the callback to ensure that we have a unique reference
274- const originalCallback = callback ;
275- callback = ( ... args : Parameters < typeof callback > ) => {
276- originalCallback ( ... args ) ;
236+ // Type assertion is safe: MapConfig<T> is a union that includes { name: K, value: T[K] }
237+ const wrappedCallback = ( config : MapConfig < T > ) => {
238+ callback ( config as { name : K ; value : T [ K ] } ) ;
277239 } ;
278240
279- if ( configName === undefined ) {
280- this . clientSubscriptions . add ( callback ) ;
281- return ( ) => {
282- this . clientSubscriptions . delete ( callback ) ;
283- } ;
284- }
285-
286241 if ( ! this . configSubscriptions . has ( configName ) ) {
287242 this . configSubscriptions . set ( configName , new Set ( ) ) ;
288243 }
289- this . configSubscriptions . get ( configName ) ! . add ( callback ) ;
244+ this . configSubscriptions . get ( configName ) ! . add ( wrappedCallback ) ;
290245
291246 return ( ) => {
292- this . configSubscriptions . get ( configName ) ?. delete ( callback ) ;
247+ this . configSubscriptions . get ( configName ) ?. delete ( wrappedCallback ) ;
293248 if ( this . configSubscriptions . get ( configName ) ?. size === 0 ) {
294249 this . configSubscriptions . delete ( configName ) ;
295250 }
@@ -378,9 +333,6 @@ export class Replane<T extends object = Record<string, unknown>> {
378333
379334 const change = { name : config . name as keyof T , value : config . value as T [ keyof T ] } ;
380335
381- for ( const callback of this . clientSubscriptions ) {
382- callback ( change ) ;
383- }
384336 for ( const callback of this . configSubscriptions . get ( config . name as keyof T ) ?? [ ] ) {
385337 callback ( change ) ;
386338 }
0 commit comments