@blac/core 2.0.0-rc-16 → 2.0.0-rc.1
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/dist/.tsbuildinfo +1 -0
- package/dist/Blac.d.ts +246 -0
- package/dist/Blac.d.ts.map +1 -0
- package/dist/Blac.js +624 -0
- package/dist/Blac.js.map +1 -0
- package/dist/Bloc.d.ts +41 -0
- package/dist/Bloc.d.ts.map +1 -0
- package/dist/Bloc.js +140 -0
- package/dist/Bloc.js.map +1 -0
- package/dist/BlocBase.d.ts +110 -0
- package/dist/BlocBase.d.ts.map +1 -0
- package/dist/BlocBase.js +287 -0
- package/dist/BlocBase.js.map +1 -0
- package/dist/Cubit.d.ts +25 -0
- package/dist/Cubit.d.ts.map +1 -0
- package/dist/Cubit.js +64 -0
- package/dist/Cubit.js.map +1 -0
- package/dist/adapter/BlacAdapter.d.ts +67 -0
- package/dist/adapter/BlacAdapter.d.ts.map +1 -0
- package/dist/adapter/BlacAdapter.js +263 -0
- package/dist/adapter/BlacAdapter.js.map +1 -0
- package/dist/adapter/ProxyFactory.d.ts +50 -0
- package/dist/adapter/ProxyFactory.d.ts.map +1 -0
- package/dist/adapter/ProxyFactory.js +150 -0
- package/dist/adapter/ProxyFactory.js.map +1 -0
- package/{src/adapter/index.ts → dist/adapter/index.d.ts} +1 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +19 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/errors/BlacError.d.ts +38 -0
- package/dist/errors/BlacError.d.ts.map +1 -0
- package/dist/errors/BlacError.js +55 -0
- package/dist/errors/BlacError.js.map +1 -0
- package/dist/errors/ErrorManager.d.ts +39 -0
- package/dist/errors/ErrorManager.d.ts.map +1 -0
- package/dist/errors/ErrorManager.js +91 -0
- package/dist/errors/ErrorManager.js.map +1 -0
- package/dist/errors/handleError.d.ts +24 -0
- package/dist/errors/handleError.d.ts.map +1 -0
- package/dist/errors/handleError.js +62 -0
- package/dist/errors/handleError.js.map +1 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +13 -0
- package/dist/errors/index.js.map +1 -0
- package/{src/events.ts → dist/events.d.ts} +4 -2
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +17 -0
- package/dist/events.js.map +1 -0
- package/dist/index.cjs +38 -0
- package/{src/index.ts → dist/index.d.ts} +1 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle/BlocLifecycle.d.ts +51 -0
- package/dist/lifecycle/BlocLifecycle.d.ts.map +1 -0
- package/dist/lifecycle/BlocLifecycle.js +123 -0
- package/dist/lifecycle/BlocLifecycle.js.map +1 -0
- package/dist/lifecycle/index.d.ts +2 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/index.js +18 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/plugins/BlocPluginRegistry.d.ts +58 -0
- package/dist/plugins/BlocPluginRegistry.d.ts.map +1 -0
- package/dist/plugins/BlocPluginRegistry.js +201 -0
- package/dist/plugins/BlocPluginRegistry.js.map +1 -0
- package/dist/plugins/SystemPluginRegistry.d.ts +79 -0
- package/dist/plugins/SystemPluginRegistry.d.ts.map +1 -0
- package/dist/plugins/SystemPluginRegistry.js +184 -0
- package/dist/plugins/SystemPluginRegistry.js.map +1 -0
- package/{src/plugins/index.ts → dist/plugins/index.d.ts} +1 -5
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +26 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/types.d.ts +103 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +3 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/subscription/SubscriptionManager.d.ts +67 -0
- package/dist/subscription/SubscriptionManager.d.ts.map +1 -0
- package/dist/subscription/SubscriptionManager.js +317 -0
- package/dist/subscription/SubscriptionManager.js.map +1 -0
- package/{src/subscription/index.ts → dist/subscription/index.d.ts} +1 -0
- package/dist/subscription/index.d.ts.map +1 -0
- package/dist/subscription/index.js +19 -0
- package/dist/subscription/index.js.map +1 -0
- package/dist/subscription/types.d.ts +65 -0
- package/dist/subscription/types.d.ts.map +1 -0
- package/dist/subscription/types.js +3 -0
- package/dist/subscription/types.js.map +1 -0
- package/dist/testing.d.ts +33 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +68 -0
- package/dist/testing.js.map +1 -0
- package/{src/types.ts → dist/types.d.ts} +11 -28
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/BatchingManager.d.ts +28 -0
- package/dist/utils/BatchingManager.d.ts.map +1 -0
- package/dist/utils/BatchingManager.js +48 -0
- package/dist/utils/BatchingManager.js.map +1 -0
- package/dist/utils/RerenderLogger.d.ts +60 -0
- package/dist/utils/RerenderLogger.d.ts.map +1 -0
- package/dist/utils/RerenderLogger.js +205 -0
- package/dist/utils/RerenderLogger.js.map +1 -0
- package/dist/utils/generateInstanceId.d.ts +11 -0
- package/dist/utils/generateInstanceId.d.ts.map +1 -0
- package/dist/utils/generateInstanceId.js +50 -0
- package/dist/utils/generateInstanceId.js.map +1 -0
- package/dist/utils/shallowEqual.d.ts +9 -0
- package/dist/utils/shallowEqual.d.ts.map +1 -0
- package/dist/utils/shallowEqual.js +35 -0
- package/dist/utils/shallowEqual.js.map +1 -0
- package/dist/utils/uuid.d.ts +10 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +24 -0
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +19 -6
- package/src/Blac.ts +0 -802
- package/src/Bloc.ts +0 -180
- package/src/BlocBase.ts +0 -398
- package/src/Cubit.ts +0 -68
- package/src/__tests__/Blac.config.test.ts +0 -79
- package/src/__tests__/Bloc.event.test.ts +0 -394
- package/src/__tests__/BlocBase.subscription.test.ts +0 -349
- package/src/__tests__/Cubit.test.ts +0 -462
- package/src/__tests__/memory-leaks.test.ts +0 -383
- package/src/__tests__/plugins.test.ts +0 -464
- package/src/adapter/BlacAdapter.ts +0 -467
- package/src/adapter/ProxyFactory.ts +0 -249
- package/src/adapter/__tests__/BlacAdapter.test.ts +0 -555
- package/src/adapter/__tests__/ProxyFactory.test.ts +0 -655
- package/src/errors/BlacError.ts +0 -69
- package/src/errors/ErrorManager.ts +0 -101
- package/src/errors/handleError.ts +0 -114
- package/src/errors/index.ts +0 -13
- package/src/lifecycle/BlocLifecycle.ts +0 -156
- package/src/lifecycle/index.ts +0 -1
- package/src/plugins/BlocPluginRegistry.ts +0 -240
- package/src/plugins/SystemPluginRegistry.ts +0 -242
- package/src/plugins/__tests__/BlocPluginRegistry.test.ts +0 -450
- package/src/plugins/__tests__/SystemPluginRegistry.test.ts +0 -404
- package/src/plugins/types.ts +0 -129
- package/src/subscription/README.md +0 -132
- package/src/subscription/SubscriptionManager.ts +0 -395
- package/src/subscription/__tests__/SubscriptionManager.test.ts +0 -355
- package/src/subscription/types.ts +0 -90
- package/src/testing.ts +0 -246
- package/src/utils/BatchingManager.ts +0 -59
- package/src/utils/RerenderLogger.ts +0 -265
- package/src/utils/__tests__/generateInstanceId.test.ts +0 -104
- package/src/utils/__tests__/shallowEqual.test.ts +0 -171
- package/src/utils/__tests__/uuid.test.ts +0 -144
- package/src/utils/generateInstanceId.ts +0 -54
- package/src/utils/shallowEqual.ts +0 -40
- package/src/utils/uuid.ts +0 -22
package/dist/Bloc.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BlocBase } from './BlocBase';
|
|
2
|
+
import { BlocEventConstraint } from './types';
|
|
3
|
+
export declare abstract class Bloc<S, // State type
|
|
4
|
+
A extends BlocEventConstraint = BlocEventConstraint> extends BlocBase<S> {
|
|
5
|
+
readonly eventHandlers: Map<new (...args: any[]) => A, (event: A, emit: (newState: S) => void) => void | Promise<void>>;
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
* Event queue to ensure sequential processing of async events
|
|
9
|
+
*/
|
|
10
|
+
private _eventQueue;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
* Flag indicating if an event is currently being processed
|
|
14
|
+
*/
|
|
15
|
+
private _isProcessingEvent;
|
|
16
|
+
/**
|
|
17
|
+
* Registers an event handler for a specific event type.
|
|
18
|
+
* This method is typically called in the constructor of a derived Bloc class.
|
|
19
|
+
* @param eventConstructor The constructor of the event to handle (e.g., LoadDataEvent).
|
|
20
|
+
* @param handler A function that processes the event and can emit new states.
|
|
21
|
+
* The 'event' parameter in the handler will be typed to the specific eventConstructor.
|
|
22
|
+
*/
|
|
23
|
+
protected on<E extends A>(eventConstructor: new (...args: any[]) => E, handler: (event: E, emit: (newState: S) => void) => void | Promise<void>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Dispatches an action/event to the Bloc.
|
|
26
|
+
* Events are queued and processed sequentially to prevent race conditions.
|
|
27
|
+
* @param action The action/event instance to be processed.
|
|
28
|
+
*/
|
|
29
|
+
add: (action: A) => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
* Processes events from the queue sequentially
|
|
33
|
+
*/
|
|
34
|
+
private _processEventQueue;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
* Processes a single event
|
|
38
|
+
*/
|
|
39
|
+
private _processEvent;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Bloc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bloc.d.ts","sourceRoot":"","sources":["../src/Bloc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,8BAAsB,IAAI,CACxB,CAAC,EAAE,aAAa;AAChB,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CACnD,SAAQ,QAAQ,CAAC,CAAC,CAAC;IACnB,QAAQ,CAAC,aAAa,EAAE,GAAG,CACzB,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACzB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAChE,CAAa;IAEd;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAW;IAE9B;;;OAGG;IACH,OAAO,CAAC,kBAAkB,CAAS;IAEnC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,EACtB,gBAAgB,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACvE,IAAI;IAeP;;;;OAIG;IACI,GAAG,GAAU,QAAQ,CAAC,KAAG,OAAO,CAAC,IAAI,CAAC,CA8B3C;IAEF;;;OAGG;YACW,kBAAkB;IAiBhC;;;OAGG;YACW,aAAa;CAmE5B"}
|
package/dist/Bloc.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bloc = void 0;
|
|
4
|
+
const Blac_1 = require("./Blac");
|
|
5
|
+
const BlocBase_1 = require("./BlocBase");
|
|
6
|
+
class Bloc extends BlocBase_1.BlocBase {
|
|
7
|
+
eventHandlers = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
* Event queue to ensure sequential processing of async events
|
|
11
|
+
*/
|
|
12
|
+
_eventQueue = [];
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
* Flag indicating if an event is currently being processed
|
|
16
|
+
*/
|
|
17
|
+
_isProcessingEvent = false;
|
|
18
|
+
/**
|
|
19
|
+
* Registers an event handler for a specific event type.
|
|
20
|
+
* This method is typically called in the constructor of a derived Bloc class.
|
|
21
|
+
* @param eventConstructor The constructor of the event to handle (e.g., LoadDataEvent).
|
|
22
|
+
* @param handler A function that processes the event and can emit new states.
|
|
23
|
+
* The 'event' parameter in the handler will be typed to the specific eventConstructor.
|
|
24
|
+
*/
|
|
25
|
+
on(eventConstructor, handler) {
|
|
26
|
+
if (this.eventHandlers.has(eventConstructor)) {
|
|
27
|
+
Blac_1.Blac.warn(`[Bloc ${this._name}:${String(this._id)}] Handler for event '${eventConstructor.name}' already registered. It will be overwritten.`);
|
|
28
|
+
}
|
|
29
|
+
this.eventHandlers.set(eventConstructor, handler);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Dispatches an action/event to the Bloc.
|
|
33
|
+
* Events are queued and processed sequentially to prevent race conditions.
|
|
34
|
+
* @param action The action/event instance to be processed.
|
|
35
|
+
*/
|
|
36
|
+
add = async (action) => {
|
|
37
|
+
// Transform event through plugins
|
|
38
|
+
let transformedAction = action;
|
|
39
|
+
try {
|
|
40
|
+
transformedAction = this._plugins.transformEvent(action);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('Error transforming event:', error);
|
|
44
|
+
// Continue with original event if transformation fails
|
|
45
|
+
}
|
|
46
|
+
// If event was cancelled by plugin, don't process it
|
|
47
|
+
if (transformedAction === null) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Notify bloc plugins of event
|
|
51
|
+
try {
|
|
52
|
+
this._plugins.notifyEvent(transformedAction);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('Error notifying plugins of event:', error);
|
|
56
|
+
}
|
|
57
|
+
// Notify system plugins of event
|
|
58
|
+
Blac_1.Blac.instance.plugins.notifyEventAdded(this, transformedAction);
|
|
59
|
+
this._eventQueue.push(transformedAction);
|
|
60
|
+
if (!this._isProcessingEvent) {
|
|
61
|
+
await this._processEventQueue();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
* Processes events from the queue sequentially
|
|
67
|
+
*/
|
|
68
|
+
async _processEventQueue() {
|
|
69
|
+
if (this._isProcessingEvent) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._isProcessingEvent = true;
|
|
73
|
+
try {
|
|
74
|
+
while (this._eventQueue.length > 0) {
|
|
75
|
+
const action = this._eventQueue.shift();
|
|
76
|
+
await this._processEvent(action);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
this._isProcessingEvent = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
* Processes a single event
|
|
86
|
+
*/
|
|
87
|
+
async _processEvent(action) {
|
|
88
|
+
const eventConstructor = action.constructor;
|
|
89
|
+
const handler = this.eventHandlers.get(eventConstructor);
|
|
90
|
+
if (handler) {
|
|
91
|
+
const emit = (newState) => {
|
|
92
|
+
const previousState = this.state; // State just before this specific emission
|
|
93
|
+
this._pushState(newState, previousState, action);
|
|
94
|
+
};
|
|
95
|
+
try {
|
|
96
|
+
await handler(action, emit);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const constructorName = action.constructor.name ||
|
|
100
|
+
'UnnamedConstructor';
|
|
101
|
+
const errorContext = {
|
|
102
|
+
blocName: this._name,
|
|
103
|
+
blocId: String(this._id),
|
|
104
|
+
eventType: constructorName,
|
|
105
|
+
currentState: this.state,
|
|
106
|
+
action: action,
|
|
107
|
+
timestamp: new Date().toISOString(),
|
|
108
|
+
};
|
|
109
|
+
Blac_1.Blac.error(`[Bloc ${this._name}:${String(this._id)}] Error in event handler for '${constructorName}':`, error, 'Context:', errorContext);
|
|
110
|
+
// Notify plugins of the error
|
|
111
|
+
if (error instanceof Error) {
|
|
112
|
+
try {
|
|
113
|
+
this._plugins.notifyError(error, {
|
|
114
|
+
phase: 'event-processing',
|
|
115
|
+
operation: 'handler',
|
|
116
|
+
metadata: { event: action },
|
|
117
|
+
});
|
|
118
|
+
Blac_1.Blac.instance.plugins.notifyError(error, this, {
|
|
119
|
+
phase: 'event-processing',
|
|
120
|
+
operation: 'handler',
|
|
121
|
+
metadata: { event: action },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (pluginError) {
|
|
125
|
+
console.error('Error notifying plugins:', pluginError);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (error instanceof Error && error.name === 'CriticalError') {
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const constructorName = action.constructor.name || 'UnnamedConstructor';
|
|
135
|
+
Blac_1.Blac.warn(`[Bloc ${this._name}:${String(this._id)}] No handler registered for action type: '${constructorName}'.`, 'Registered handlers:', Array.from(this.eventHandlers.keys()).map((k) => k.name), 'Action was:', action);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.Bloc = Bloc;
|
|
140
|
+
//# sourceMappingURL=Bloc.js.map
|
package/dist/Bloc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bloc.js","sourceRoot":"","sources":["../src/Bloc.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,yCAAsC;AAGtC,MAAsB,IAGpB,SAAQ,mBAAW;IACV,aAAa,GAGlB,IAAI,GAAG,EAAE,CAAC;IAEd;;;OAGG;IACK,WAAW,GAAQ,EAAE,CAAC;IAE9B;;;OAGG;IACK,kBAAkB,GAAG,KAAK,CAAC;IAEnC;;;;;;OAMG;IACO,EAAE,CACV,gBAA2C,EAC3C,OAAwE;QAExE,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,gBA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CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EACxD,aAAa,EACb,MAAM,CACP,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA/KD,oBA+KC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { BlocPlugin } from './plugins/types';
|
|
2
|
+
import { BlocPluginRegistry } from './plugins/BlocPluginRegistry';
|
|
3
|
+
import { SubscriptionManager } from './subscription/SubscriptionManager';
|
|
4
|
+
import { BlocLifecycleState, StateTransitionResult } from './lifecycle/BlocLifecycle';
|
|
5
|
+
import type { Blac } from './Blac';
|
|
6
|
+
export type BlocInstanceId = string | number | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Base class for both Blocs and Cubits using unified subscription model.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class BlocBase<S> {
|
|
11
|
+
uid: string;
|
|
12
|
+
blacInstance?: Blac;
|
|
13
|
+
static isolated: boolean;
|
|
14
|
+
get isIsolated(): boolean;
|
|
15
|
+
static keepAlive: boolean;
|
|
16
|
+
get isKeepAlive(): boolean;
|
|
17
|
+
_isolated: boolean;
|
|
18
|
+
_id: BlocInstanceId;
|
|
19
|
+
_instanceRef?: string;
|
|
20
|
+
_name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Unified subscription manager for all state notifications
|
|
23
|
+
*/
|
|
24
|
+
_subscriptionManager: SubscriptionManager<S>;
|
|
25
|
+
_state: S;
|
|
26
|
+
private _lifecycleManager;
|
|
27
|
+
private _batchingManager;
|
|
28
|
+
_keepAlive: boolean;
|
|
29
|
+
lastUpdate?: number;
|
|
30
|
+
_plugins: BlocPluginRegistry<S, any>;
|
|
31
|
+
onDispose?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new BlocBase instance with unified subscription management
|
|
34
|
+
*/
|
|
35
|
+
constructor(initialState: S);
|
|
36
|
+
/**
|
|
37
|
+
* Returns the current state
|
|
38
|
+
*/
|
|
39
|
+
get state(): S;
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe to all state changes
|
|
42
|
+
*/
|
|
43
|
+
subscribe(callback: (state: S) => void): () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe with a selector for optimized updates
|
|
46
|
+
*/
|
|
47
|
+
subscribeWithSelector<T>(selector: (state: S) => T, callback: (value: T) => void, equalityFn?: (a: T, b: T) => boolean): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Subscribe with React component reference for automatic cleanup
|
|
50
|
+
*/
|
|
51
|
+
subscribeComponent(componentRef: WeakRef<object>, callback: () => void): () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Get current subscription count
|
|
54
|
+
*/
|
|
55
|
+
get subscriptionCount(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Track property access for a subscription
|
|
58
|
+
*/
|
|
59
|
+
trackAccess(subscriptionId: string, path: string, value?: unknown): void;
|
|
60
|
+
/**
|
|
61
|
+
* Emit a new state
|
|
62
|
+
*/
|
|
63
|
+
protected emit(newState: S, action?: unknown): void;
|
|
64
|
+
/**
|
|
65
|
+
* Internal state push method used by Bloc
|
|
66
|
+
*/
|
|
67
|
+
_pushState(newState: S, oldState: S, action?: unknown): void;
|
|
68
|
+
_batchUpdates(callback: () => void): void;
|
|
69
|
+
/**
|
|
70
|
+
* Add a plugin
|
|
71
|
+
*/
|
|
72
|
+
addPlugin(plugin: BlocPlugin<S, any>): void;
|
|
73
|
+
/**
|
|
74
|
+
* Remove a plugin
|
|
75
|
+
*/
|
|
76
|
+
removePlugin(plugin: BlocPlugin<S, any>): void;
|
|
77
|
+
/**
|
|
78
|
+
* Get all plugins
|
|
79
|
+
*/
|
|
80
|
+
get plugins(): ReadonlyArray<BlocPlugin<S, any>>;
|
|
81
|
+
/**
|
|
82
|
+
* Disposal management
|
|
83
|
+
*/
|
|
84
|
+
get isDisposed(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Atomic state transition for disposal
|
|
87
|
+
*/
|
|
88
|
+
_atomicStateTransition(expectedState: BlocLifecycleState, newState: BlocLifecycleState): StateTransitionResult;
|
|
89
|
+
/**
|
|
90
|
+
* Dispose the bloc and clean up resources
|
|
91
|
+
*/
|
|
92
|
+
dispose(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Schedule disposal when no subscriptions remain
|
|
95
|
+
*/
|
|
96
|
+
_scheduleDisposal(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Set disposal handler
|
|
99
|
+
*/
|
|
100
|
+
setDisposalHandler(handler: (bloc: BlocBase<unknown>) => void): void;
|
|
101
|
+
/**
|
|
102
|
+
* Check if disposal should be scheduled (called by subscription manager)
|
|
103
|
+
*/
|
|
104
|
+
checkDisposal(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Cancel disposal if bloc is in disposal_requested state
|
|
107
|
+
*/
|
|
108
|
+
_cancelDisposalIfRequested(): void;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=BlocBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlocBase.d.ts","sourceRoot":"","sources":["../src/BlocBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAEL,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAQzD;;GAEG;AACH,8BAAsB,QAAQ,CAAC,CAAC;IACvB,GAAG,SAAkB;IAC5B,YAAY,CAAC,EAAE,IAAI,CAAC;IAEpB,MAAM,CAAC,QAAQ,UAAS;IACxB,IA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AAQ,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IAInD;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IA+C5D,aAAa,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAUzC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI;IAa3C;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI;IAI9C;;OAEG;IACH,IAAI,OAAO,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAE/C;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,sBAAsB,CACpB,aAAa,EAAE,kBAAkB,EACjC,QAAQ,EAAE,kBAAkB,GAC3B,qBAAqB;IAOxB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAqD9B;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAezB;;OAEG;IACH,kBAAkB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,IAAI;IAMpE;;OAEG;IACH,aAAa,IAAI,IAAI;IAUrB;;OAEG;IACH,0BAA0B,IAAI,IAAI;CAwBnC"}
|
package/dist/BlocBase.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlocBase = void 0;
|
|
4
|
+
const uuid_1 = require("./utils/uuid");
|
|
5
|
+
const BlocPluginRegistry_1 = require("./plugins/BlocPluginRegistry");
|
|
6
|
+
const SubscriptionManager_1 = require("./subscription/SubscriptionManager");
|
|
7
|
+
const BlocLifecycle_1 = require("./lifecycle/BlocLifecycle");
|
|
8
|
+
const BatchingManager_1 = require("./utils/BatchingManager");
|
|
9
|
+
/**
|
|
10
|
+
* Base class for both Blocs and Cubits using unified subscription model.
|
|
11
|
+
*/
|
|
12
|
+
class BlocBase {
|
|
13
|
+
uid = (0, uuid_1.generateUUID)();
|
|
14
|
+
blacInstance;
|
|
15
|
+
static isolated = false;
|
|
16
|
+
get isIsolated() {
|
|
17
|
+
return this._isolated;
|
|
18
|
+
}
|
|
19
|
+
static keepAlive = false;
|
|
20
|
+
get isKeepAlive() {
|
|
21
|
+
return this._keepAlive;
|
|
22
|
+
}
|
|
23
|
+
_isolated = false;
|
|
24
|
+
_id;
|
|
25
|
+
_instanceRef;
|
|
26
|
+
_name;
|
|
27
|
+
/**
|
|
28
|
+
* Unified subscription manager for all state notifications
|
|
29
|
+
*/
|
|
30
|
+
_subscriptionManager;
|
|
31
|
+
_state;
|
|
32
|
+
_lifecycleManager = new BlocLifecycle_1.BlocLifecycleManager();
|
|
33
|
+
_batchingManager = new BatchingManager_1.BatchingManager();
|
|
34
|
+
_keepAlive = false;
|
|
35
|
+
lastUpdate;
|
|
36
|
+
_plugins = new BlocPluginRegistry_1.BlocPluginRegistry();
|
|
37
|
+
onDispose;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new BlocBase instance with unified subscription management
|
|
40
|
+
*/
|
|
41
|
+
constructor(initialState) {
|
|
42
|
+
this._state = initialState;
|
|
43
|
+
this._id = this.constructor.name;
|
|
44
|
+
this._name = this.constructor.name;
|
|
45
|
+
// Initialize unified subscription system
|
|
46
|
+
this._subscriptionManager = new SubscriptionManager_1.SubscriptionManager(this);
|
|
47
|
+
// Access static properties
|
|
48
|
+
const Constructor = this.constructor;
|
|
49
|
+
this._keepAlive =
|
|
50
|
+
typeof Constructor.keepAlive === 'boolean'
|
|
51
|
+
? Constructor.keepAlive
|
|
52
|
+
: false;
|
|
53
|
+
this._isolated =
|
|
54
|
+
typeof Constructor.isolated === 'boolean' ? Constructor.isolated : false;
|
|
55
|
+
// Initialize plugin registry
|
|
56
|
+
this._plugins = new BlocPluginRegistry_1.BlocPluginRegistry();
|
|
57
|
+
// Register static plugins
|
|
58
|
+
if (Constructor.plugins && Array.isArray(Constructor.plugins)) {
|
|
59
|
+
for (const plugin of Constructor.plugins) {
|
|
60
|
+
this._plugins.add(plugin);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Attach all plugins
|
|
64
|
+
this._plugins.attach(this);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the current state
|
|
68
|
+
*/
|
|
69
|
+
get state() {
|
|
70
|
+
if (this._lifecycleManager.isDisposed) {
|
|
71
|
+
return this._state; // Return last known state for disposed blocs
|
|
72
|
+
}
|
|
73
|
+
return this._state;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Subscribe to all state changes
|
|
77
|
+
*/
|
|
78
|
+
subscribe(callback) {
|
|
79
|
+
return this._subscriptionManager.subscribe({
|
|
80
|
+
type: 'observer',
|
|
81
|
+
notify: (state) => callback(state),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Subscribe with a selector for optimized updates
|
|
86
|
+
*/
|
|
87
|
+
subscribeWithSelector(selector, callback, equalityFn) {
|
|
88
|
+
return this._subscriptionManager.subscribe({
|
|
89
|
+
type: 'consumer',
|
|
90
|
+
selector: selector,
|
|
91
|
+
equalityFn: equalityFn,
|
|
92
|
+
notify: (value) => callback(value),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Subscribe with React component reference for automatic cleanup
|
|
97
|
+
*/
|
|
98
|
+
subscribeComponent(componentRef, callback) {
|
|
99
|
+
return this._subscriptionManager.subscribe({
|
|
100
|
+
type: 'consumer',
|
|
101
|
+
weakRef: componentRef,
|
|
102
|
+
notify: callback,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get current subscription count
|
|
107
|
+
*/
|
|
108
|
+
get subscriptionCount() {
|
|
109
|
+
return this._subscriptionManager.size;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Track property access for a subscription
|
|
113
|
+
*/
|
|
114
|
+
trackAccess(subscriptionId, path, value) {
|
|
115
|
+
this._subscriptionManager.trackAccess(subscriptionId, path, value);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Emit a new state
|
|
119
|
+
*/
|
|
120
|
+
emit(newState, action) {
|
|
121
|
+
this._pushState(newState, this._state, action);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Internal state push method used by Bloc
|
|
125
|
+
*/
|
|
126
|
+
_pushState(newState, oldState, action) {
|
|
127
|
+
// Validate state emission conditions
|
|
128
|
+
if (this._lifecycleManager.currentState !== BlocLifecycle_1.BlocLifecycleState.ACTIVE) {
|
|
129
|
+
this.blacInstance?.error(`[${this._name}:${this._id}] Attempted state update on ${this._lifecycleManager.currentState} bloc. Update ignored.`);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (newState === undefined) {
|
|
133
|
+
return; // Silent failure for undefined states
|
|
134
|
+
}
|
|
135
|
+
this._state = newState;
|
|
136
|
+
// Apply plugins
|
|
137
|
+
const transformedState = this._plugins.transformState(oldState, newState);
|
|
138
|
+
this._state = transformedState;
|
|
139
|
+
// Notify plugins of state change
|
|
140
|
+
this._plugins.notifyStateChange(oldState, transformedState);
|
|
141
|
+
// Notify system plugins of state change
|
|
142
|
+
this.blacInstance?.plugins.notifyStateChanged(this, oldState, transformedState);
|
|
143
|
+
// Handle batching
|
|
144
|
+
if (this._batchingManager.isCurrentlyBatching) {
|
|
145
|
+
this._batchingManager.addUpdate({
|
|
146
|
+
newState: transformedState,
|
|
147
|
+
oldState,
|
|
148
|
+
action,
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Notify all subscriptions
|
|
153
|
+
this._subscriptionManager.notify(transformedState, oldState, action);
|
|
154
|
+
this.lastUpdate = Date.now();
|
|
155
|
+
}
|
|
156
|
+
_batchUpdates(callback) {
|
|
157
|
+
this._batchingManager.batchUpdates(callback, (finalUpdate) => {
|
|
158
|
+
this._subscriptionManager.notify(finalUpdate.newState, finalUpdate.oldState, finalUpdate.action);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Add a plugin
|
|
163
|
+
*/
|
|
164
|
+
addPlugin(plugin) {
|
|
165
|
+
this._plugins.add(plugin);
|
|
166
|
+
// If plugins are already attached (bloc is active), attach the new plugin
|
|
167
|
+
if (this._plugins.attached && plugin.onAttach) {
|
|
168
|
+
try {
|
|
169
|
+
plugin.onAttach(this);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
console.error(`Plugin '${plugin.name}' error in onAttach:`, error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Remove a plugin
|
|
178
|
+
*/
|
|
179
|
+
removePlugin(plugin) {
|
|
180
|
+
this._plugins.remove(plugin.name);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get all plugins
|
|
184
|
+
*/
|
|
185
|
+
get plugins() {
|
|
186
|
+
return this._plugins.getAll();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Disposal management
|
|
190
|
+
*/
|
|
191
|
+
get isDisposed() {
|
|
192
|
+
return this._lifecycleManager.isDisposed;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Atomic state transition for disposal
|
|
196
|
+
*/
|
|
197
|
+
_atomicStateTransition(expectedState, newState) {
|
|
198
|
+
return this._lifecycleManager.atomicStateTransition(expectedState, newState);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Dispose the bloc and clean up resources
|
|
202
|
+
*/
|
|
203
|
+
async dispose() {
|
|
204
|
+
const transitionResult = this._lifecycleManager.atomicStateTransition(BlocLifecycle_1.BlocLifecycleState.ACTIVE, BlocLifecycle_1.BlocLifecycleState.DISPOSING);
|
|
205
|
+
if (!transitionResult.success) {
|
|
206
|
+
if (this._lifecycleManager.currentState ===
|
|
207
|
+
BlocLifecycle_1.BlocLifecycleState.DISPOSAL_REQUESTED) {
|
|
208
|
+
this._lifecycleManager.atomicStateTransition(BlocLifecycle_1.BlocLifecycleState.DISPOSAL_REQUESTED, BlocLifecycle_1.BlocLifecycleState.DISPOSING);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
// Clear subscriptions
|
|
216
|
+
this._subscriptionManager.clear();
|
|
217
|
+
// Call disposal hook
|
|
218
|
+
if (this.onDispose) {
|
|
219
|
+
this.onDispose();
|
|
220
|
+
}
|
|
221
|
+
// Notify plugins of disposal
|
|
222
|
+
for (const plugin of this._plugins.getAll()) {
|
|
223
|
+
try {
|
|
224
|
+
if ('onDispose' in plugin && typeof plugin.onDispose === 'function') {
|
|
225
|
+
plugin.onDispose(this);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
console.error('Plugin disposal error:', error);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Call disposal handler
|
|
233
|
+
const handler = this._lifecycleManager.getDisposalHandler();
|
|
234
|
+
if (handler) {
|
|
235
|
+
handler(this);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
this._lifecycleManager.atomicStateTransition(BlocLifecycle_1.BlocLifecycleState.DISPOSING, BlocLifecycle_1.BlocLifecycleState.DISPOSED);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Schedule disposal when no subscriptions remain
|
|
244
|
+
*/
|
|
245
|
+
_scheduleDisposal() {
|
|
246
|
+
const shouldDispose = this._subscriptionManager.size === 0 && !this._keepAlive;
|
|
247
|
+
if (!shouldDispose) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this._lifecycleManager.scheduleDisposal(16, () => this._subscriptionManager.size === 0 && !this._keepAlive, () => this.dispose());
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Set disposal handler
|
|
254
|
+
*/
|
|
255
|
+
setDisposalHandler(handler) {
|
|
256
|
+
this._lifecycleManager.setDisposalHandler(handler);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Check if disposal should be scheduled (called by subscription manager)
|
|
260
|
+
*/
|
|
261
|
+
checkDisposal() {
|
|
262
|
+
if (this._subscriptionManager.size === 0 &&
|
|
263
|
+
!this._keepAlive &&
|
|
264
|
+
this._lifecycleManager.currentState === BlocLifecycle_1.BlocLifecycleState.ACTIVE) {
|
|
265
|
+
this._scheduleDisposal();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Cancel disposal if bloc is in disposal_requested state
|
|
270
|
+
*/
|
|
271
|
+
_cancelDisposalIfRequested() {
|
|
272
|
+
this.blacInstance?.log(`[${this._name}:${this._id}] _cancelDisposalIfRequested called. Current state: ${this._lifecycleManager.currentState}`);
|
|
273
|
+
const success = this._lifecycleManager.cancelDisposal();
|
|
274
|
+
if (success) {
|
|
275
|
+
this.blacInstance?.log(`[${this._name}:${this._id}] Disposal cancelled - new subscription added`);
|
|
276
|
+
}
|
|
277
|
+
else if (this._lifecycleManager.currentState ===
|
|
278
|
+
BlocLifecycle_1.BlocLifecycleState.DISPOSAL_REQUESTED) {
|
|
279
|
+
this.blacInstance?.warn(`[${this._name}:${this._id}] Failed to cancel disposal. Current state: ${this._lifecycleManager.currentState}`);
|
|
280
|
+
}
|
|
281
|
+
else if (this._lifecycleManager.isDisposed) {
|
|
282
|
+
this.blacInstance?.error(`[${this._name}:${this._id}] Cannot cancel disposal - bloc is already disposed`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286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/Cubit.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BlocBase } from './BlocBase';
|
|
2
|
+
/**
|
|
3
|
+
* A Cubit is a simpler version of a Bloc that doesn't handle events.
|
|
4
|
+
* It manages state and provides methods to update it.
|
|
5
|
+
* @template S - The type of state this Cubit manages
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Cubit<S> extends BlocBase<S> {
|
|
8
|
+
/**
|
|
9
|
+
* Updates the current state and notifies all observers of the change.
|
|
10
|
+
* If the new state is identical to the current state (using Object.is),
|
|
11
|
+
* no update will occur.
|
|
12
|
+
* @param state - The new state to set
|
|
13
|
+
*/
|
|
14
|
+
emit(state: S): void;
|
|
15
|
+
/**
|
|
16
|
+
* Partially updates the current state by merging it with the provided state patch.
|
|
17
|
+
* This method is only applicable when the state is an object type.
|
|
18
|
+
*
|
|
19
|
+
* @param statePatch - A partial state object containing only the properties to update
|
|
20
|
+
* @param ignoreChangeCheck - If true, skips checking if the state has actually changed
|
|
21
|
+
* @throws {TypeError} If the state is not an object type
|
|
22
|
+
*/
|
|
23
|
+
patch(statePatch: S extends object ? Partial<S> : S, ignoreChangeCheck?: boolean): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=Cubit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cubit.d.ts","sourceRoot":"","sources":["../src/Cubit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;GAIG;AACH,8BAAsB,KAAK,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAChD;;;;;OAKG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAUpB;;;;;;;OAOG;IACH,KAAK,CACH,UAAU,EAAE,CAAC,SAAS,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAC7C,iBAAiB,UAAQ,GACxB,IAAI;CA+BR"}
|