@blac/core 2.0.0-rc-7 → 2.0.0-rc-8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/BlocBase.ts CHANGED
@@ -2,7 +2,7 @@ import { BlacObservable } from './BlacObserver';
2
2
  import { generateUUID } from './utils/uuid';
3
3
 
4
4
  export type BlocInstanceId = string | number | undefined;
5
- type DependencySelector<S> = (newState: S) => unknown[][];
5
+ type DependencySelector<S> = (currentState: S, previousState: S | undefined, instance: any) => unknown[];
6
6
 
7
7
  // Define an interface for the static properties expected on a Bloc/Cubit constructor
8
8
  interface BlocStaticProperties {
@@ -264,6 +264,9 @@ export abstract class BlocBase<
264
264
  this._consumerRefs.set(consumerId, new WeakRef(consumerRef));
265
265
  }
266
266
 
267
+ // @ts-ignore - Blac is available globally
268
+ (globalThis as any).Blac?.log(`[${this._name}:${this._id}] Consumer added. Total consumers: ${this._consumers.size}`);
269
+
267
270
  // this._blac.dispatchEvent(BlacLifecycleEvent.BLOC_CONSUMER_ADDED, this, { consumerId });
268
271
  };
269
272
 
@@ -281,8 +284,13 @@ export abstract class BlocBase<
281
284
  this._consumerRefs.delete(consumerId);
282
285
  // this._blac.dispatchEvent(BlacLifecycleEvent.BLOC_CONSUMER_REMOVED, this, { consumerId });
283
286
 
287
+ // @ts-ignore - Blac is available globally
288
+ (globalThis as any).Blac?.log(`[${this._name}:${this._id}] Consumer removed. Remaining consumers: ${this._consumers.size}, keepAlive: ${this._keepAlive}`);
289
+
284
290
  // If no consumers remain and not keep-alive, schedule disposal
285
291
  if (this._consumers.size === 0 && !this._keepAlive && this._disposalState === 'active') {
292
+ // @ts-ignore - Blac is available globally
293
+ (globalThis as any).Blac?.log(`[${this._name}:${this._id}] No consumers left and not keep-alive. Scheduling disposal.`);
286
294
  this._scheduleDisposal();
287
295
  }
288
296
  };
package/src/types.ts CHANGED
@@ -77,9 +77,16 @@ export interface BlocErrorBoundary<S, A extends BlocEventConstraint> {
77
77
 
78
78
  /**
79
79
  * Function type for determining dependencies that trigger re-renders
80
+ * Similar to React's useEffect dependency array - if any dependency changes, a re-render is triggered
80
81
  * @template S The state type
81
- * @returns Array of dependency arrays - if any dependency in any array changes, a re-render is triggered
82
+ * @template I The bloc instance type
83
+ * @param currentState The current state
84
+ * @param previousState The previous state (undefined on first call)
85
+ * @param instance The bloc instance
86
+ * @returns Array of dependencies - if any dependency changes, a re-render is triggered
82
87
  */
83
- export type BlocHookDependencyArrayFn<S> = (
84
- newState: S
85
- ) => unknown[][];
88
+ export type BlocHookDependencyArrayFn<S, I = any> = (
89
+ currentState: S,
90
+ previousState: S | undefined,
91
+ instance: I
92
+ ) => unknown[];