@blac/core 2.0.0-rc-2 → 2.0.0-rc-3
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/README.md +53 -45
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +7 -98
- package/dist/index.es.js +215 -313
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Blac.ts +40 -107
- package/src/BlacObserver.ts +12 -6
- package/src/BlocBase.ts +13 -32
- package/src/index.ts +2 -3
- package/src/BlacObservable.ts +0 -85
- package/src/BlacPlugin.ts +0 -13
- package/src/addons/BlacAddon.ts +0 -17
- package/src/addons/Persist.ts +0 -105
- package/src/addons/index.ts +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Main Blac class that manages the state management system.
|
|
3
3
|
* Implements a singleton pattern to ensure only one instance exists.
|
|
4
|
-
* Handles bloc lifecycle,
|
|
4
|
+
* Handles bloc lifecycle, and instance tracking.
|
|
5
5
|
*
|
|
6
6
|
* Key responsibilities:
|
|
7
7
|
* - Managing bloc instances (creation, disposal, lookup)
|
|
8
8
|
* - Handling isolated and non-isolated blocs
|
|
9
|
-
* - Managing plugins and lifecycle events
|
|
10
9
|
* - Providing logging and debugging capabilities
|
|
11
10
|
*/
|
|
12
11
|
export declare class Blac {
|
|
@@ -17,12 +16,10 @@ export declare class Blac {
|
|
|
17
16
|
static getAllBlocs: <B extends BlocConstructor<unknown>>(blocClass: B, options?: {
|
|
18
17
|
searchIsolated?: boolean;
|
|
19
18
|
}) => InstanceType<B>[];
|
|
20
|
-
static addPlugin: (plugin: BlacPlugin) => void;
|
|
21
19
|
/** Map storing all registered bloc instances by their class name and ID */
|
|
22
20
|
blocInstanceMap: Map<string, BlocBase<any>>;
|
|
23
21
|
/** Map storing isolated bloc instances grouped by their constructor */
|
|
24
22
|
isolatedBlocMap: Map<BlocConstructor<any>, BlocBase<any>[]>;
|
|
25
|
-
pluginList: BlacPlugin[];
|
|
26
23
|
/** Flag to control whether changes should be posted to document */
|
|
27
24
|
postChangesToDocument: boolean;
|
|
28
25
|
/**
|
|
@@ -65,31 +62,6 @@ export declare class Blac {
|
|
|
65
62
|
*/
|
|
66
63
|
resetInstance: () => void;
|
|
67
64
|
static resetInstance: () => void;
|
|
68
|
-
/**
|
|
69
|
-
* Adds a plugin to the Blac instance
|
|
70
|
-
* @param plugin - The plugin to add
|
|
71
|
-
*/
|
|
72
|
-
addPlugin: (plugin: BlacPlugin) => void;
|
|
73
|
-
/**
|
|
74
|
-
* Dispatches a lifecycle event to all registered plugins
|
|
75
|
-
* @param event - The lifecycle event to dispatch
|
|
76
|
-
* @param bloc - The bloc instance involved in the event
|
|
77
|
-
* @param params - Additional parameters for the event
|
|
78
|
-
*/
|
|
79
|
-
dispatchEventToPlugins: (event: BlacLifecycleEvent, bloc: BlocBase<any>, params?: unknown) => void;
|
|
80
|
-
/**
|
|
81
|
-
* Dispatches a lifecycle event and handles related cleanup actions.
|
|
82
|
-
* This method is responsible for:
|
|
83
|
-
* - Logging the event
|
|
84
|
-
* - Handling bloc disposal when needed
|
|
85
|
-
* - Managing bloc consumer cleanup
|
|
86
|
-
* - Forwarding the event to plugins
|
|
87
|
-
*
|
|
88
|
-
* @param event - The lifecycle event to dispatch
|
|
89
|
-
* @param bloc - The bloc instance involved in the event
|
|
90
|
-
* @param params - Additional parameters for the event
|
|
91
|
-
*/
|
|
92
|
-
dispatchEvent: (event: BlacLifecycleEvent, bloc: BlocBase<any>, params?: unknown) => void;
|
|
93
65
|
/**
|
|
94
66
|
* Disposes of a bloc instance by removing it from the appropriate registry
|
|
95
67
|
* @param bloc - The bloc instance to dispose
|
|
@@ -142,6 +114,8 @@ export declare class Blac {
|
|
|
142
114
|
* @returns The newly created bloc instance
|
|
143
115
|
*/
|
|
144
116
|
createNewBlocInstance<B extends BlocConstructor<BlocBase<any>>>(blocClass: B, id: BlocInstanceId, options?: GetBlocOptions<InstanceType<B>>): InstanceType<B>;
|
|
117
|
+
activateBloc: (bloc: BlocBase<any>) => void;
|
|
118
|
+
static activateBloc: (bloc: BlocBase<any>) => void;
|
|
145
119
|
/**
|
|
146
120
|
* Gets or creates a bloc instance based on the provided class and options.
|
|
147
121
|
* If a bloc with the given ID exists, it will be returned. Otherwise, a new instance will be created.
|
|
@@ -185,20 +159,6 @@ export declare class Blac {
|
|
|
185
159
|
}) => InstanceType<B>[];
|
|
186
160
|
}
|
|
187
161
|
|
|
188
|
-
declare type BlacAddon = {
|
|
189
|
-
name: string;
|
|
190
|
-
onInit?: BlacAddonInit;
|
|
191
|
-
onEmit?: BlacAddonEmit;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
declare type BlacAddonEmit = (params: {
|
|
195
|
-
oldState: unknown;
|
|
196
|
-
newState: unknown;
|
|
197
|
-
cubit: BlocBase<any>;
|
|
198
|
-
}) => void;
|
|
199
|
-
|
|
200
|
-
declare type BlacAddonInit = (bloc: BlocBase<any>) => void;
|
|
201
|
-
|
|
202
162
|
/**
|
|
203
163
|
* Configuration options for the Blac instance
|
|
204
164
|
*/
|
|
@@ -207,20 +167,6 @@ export declare interface BlacConfig {
|
|
|
207
167
|
exposeBlacInstance?: boolean;
|
|
208
168
|
}
|
|
209
169
|
|
|
210
|
-
/**
|
|
211
|
-
* Enum representing different lifecycle events that can occur in the Blac system.
|
|
212
|
-
* These events are used to track the lifecycle of blocs and their consumers.
|
|
213
|
-
*/
|
|
214
|
-
export declare enum BlacLifecycleEvent {
|
|
215
|
-
BLOC_DISPOSED = "BLOC_DISPOSED",
|
|
216
|
-
BLOC_CREATED = "BLOC_CREATED",
|
|
217
|
-
LISTENER_REMOVED = "LISTENER_REMOVED",
|
|
218
|
-
LISTENER_ADDED = "LISTENER_ADDED",
|
|
219
|
-
STATE_CHANGED = "STATE_CHANGED",
|
|
220
|
-
BLOC_CONSUMER_REMOVED = "BLOC_CONSUMER_REMOVED",
|
|
221
|
-
BLOC_CONSUMER_ADDED = "BLOC_CONSUMER_ADDED"
|
|
222
|
-
}
|
|
223
|
-
|
|
224
170
|
/**
|
|
225
171
|
* A class that manages observers for a Bloc's state changes
|
|
226
172
|
* @template S - The type of state being observed
|
|
@@ -263,9 +209,9 @@ export declare class BlacObservable<S = unknown> {
|
|
|
263
209
|
*/
|
|
264
210
|
notify(newState: S, oldState: S, action?: unknown): void;
|
|
265
211
|
/**
|
|
266
|
-
*
|
|
212
|
+
* Clears the observer set
|
|
267
213
|
*/
|
|
268
|
-
|
|
214
|
+
clear(): void;
|
|
269
215
|
}
|
|
270
216
|
|
|
271
217
|
/**
|
|
@@ -285,11 +231,6 @@ export declare type BlacObserver<S> = {
|
|
|
285
231
|
id: string;
|
|
286
232
|
};
|
|
287
233
|
|
|
288
|
-
export declare interface BlacPlugin {
|
|
289
|
-
name: string;
|
|
290
|
-
onEvent(event: BlacLifecycleEvent, bloc: BlocBase<any>, params?: unknown): void;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
234
|
export declare abstract class Bloc<S, // State type
|
|
294
235
|
A extends object, // Base Action/Event type, constrained to object
|
|
295
236
|
P = unknown> extends BlocBase<S, P> {
|
|
@@ -320,6 +261,7 @@ P = unknown> extends BlocBase<S, P> {
|
|
|
320
261
|
* @template P The type of props that can be passed during instance creation (optional)
|
|
321
262
|
*/
|
|
322
263
|
export declare abstract class BlocBase<S, P = unknown> {
|
|
264
|
+
uid: `${string}-${string}-${string}-${string}-${string}`;
|
|
323
265
|
/**
|
|
324
266
|
* When true, every consumer will receive its own unique instance of this Bloc.
|
|
325
267
|
* Use this when state should not be shared between components.
|
|
@@ -339,7 +281,6 @@ export declare abstract class BlocBase<S, P = unknown> {
|
|
|
339
281
|
* When provided, observers will only be notified when selected dependencies change.
|
|
340
282
|
*/
|
|
341
283
|
defaultDependencySelector: DependencySelector<S> | undefined;
|
|
342
|
-
/* Excluded from this release type: _addons */
|
|
343
284
|
/* Excluded from this release type: _isolated */
|
|
344
285
|
/* Excluded from this release type: _observer */
|
|
345
286
|
/* Excluded from this release type: _blac */
|
|
@@ -381,7 +322,6 @@ export declare abstract class BlocBase<S, P = unknown> {
|
|
|
381
322
|
/* Excluded from this release type: _consumers */
|
|
382
323
|
/* Excluded from this release type: _addConsumer */
|
|
383
324
|
/* Excluded from this release type: _removeConsumer */
|
|
384
|
-
/* Excluded from this release type: _connectAddons */
|
|
385
325
|
lastUpdate: number;
|
|
386
326
|
/* Excluded from this release type: _pushState */
|
|
387
327
|
}
|
|
@@ -456,6 +396,7 @@ export declare interface GetBlocOptions<B extends BlocBase<any>> {
|
|
|
456
396
|
props?: InferPropsFromGeneric<B>;
|
|
457
397
|
onMount?: (bloc: B) => void;
|
|
458
398
|
instanceRef?: string;
|
|
399
|
+
throwIfNotFound?: boolean;
|
|
459
400
|
}
|
|
460
401
|
|
|
461
402
|
/**
|
|
@@ -464,38 +405,6 @@ export declare interface GetBlocOptions<B extends BlocBase<any>> {
|
|
|
464
405
|
*/
|
|
465
406
|
export declare type InferPropsFromGeneric<T> = T extends Bloc<any, any, infer P> ? P : T extends Cubit<any, infer P> ? P : never;
|
|
466
407
|
|
|
467
|
-
/**
|
|
468
|
-
* Persist addon
|
|
469
|
-
*
|
|
470
|
-
* @param options
|
|
471
|
-
* @returns BlacAddon
|
|
472
|
-
*/
|
|
473
|
-
export declare function Persist(options?: {
|
|
474
|
-
/**
|
|
475
|
-
* @default 'blac'
|
|
476
|
-
*/
|
|
477
|
-
keyPrefix?: string;
|
|
478
|
-
/**
|
|
479
|
-
* @default the bloc's id
|
|
480
|
-
*/
|
|
481
|
-
keyName?: string;
|
|
482
|
-
/**
|
|
483
|
-
* Used when the value is not found in storage
|
|
484
|
-
*/
|
|
485
|
-
defaultValue?: unknown;
|
|
486
|
-
/**
|
|
487
|
-
* @default 'localStorage'
|
|
488
|
-
* @see StorageType
|
|
489
|
-
*/
|
|
490
|
-
storageType?: StorageType;
|
|
491
|
-
/**
|
|
492
|
-
* @default false
|
|
493
|
-
*/
|
|
494
|
-
onError?: (e: unknown) => void;
|
|
495
|
-
}): BlacAddon;
|
|
496
|
-
|
|
497
|
-
declare type StorageType = 'localStorage' | 'sessionStorage';
|
|
498
|
-
|
|
499
408
|
/**
|
|
500
409
|
* Extracts the state type from a BlocBase instance
|
|
501
410
|
* @template B - The BlocBase type to extract the state from
|