@portento/core 0.2.0

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/index.mjs ADDED
@@ -0,0 +1,732 @@
1
+ // src/DependencyManagement.ts
2
+ import { container as tsyringe, Lifecycle } from "tsyringe";
3
+ import { configure } from "mobx";
4
+ var DependencyManagement = class _DependencyManagement {
5
+ constructor() {
6
+ // Single global container for all registrations
7
+ this.container = tsyringe.createChildContainer();
8
+ // Scope tracking maps: className -> Symbol token
9
+ this.rootScope = /* @__PURE__ */ new Map();
10
+ // Router scopes: routerSelector -> (className -> Symbol token)
11
+ this.routerScopes = /* @__PURE__ */ new Map();
12
+ // Component scopes: componentSelector -> (className -> Symbol token)
13
+ this.componentScopes = /* @__PURE__ */ new Map();
14
+ // Component-to-Router membership tracking
15
+ this.componentToRouter = /* @__PURE__ */ new Map();
16
+ // Store class references for re-registration after reset
17
+ this.rootClasses = /* @__PURE__ */ new Map();
18
+ this.routerClasses = /* @__PURE__ */ new Map();
19
+ this.componentClasses = /* @__PURE__ */ new Map();
20
+ configure({ useProxies: "always" });
21
+ this.container.register("DependencyManagement", {
22
+ useValue: this
23
+ });
24
+ }
25
+ static getInstance() {
26
+ if (!_DependencyManagement.instance) {
27
+ _DependencyManagement.instance = new _DependencyManagement();
28
+ }
29
+ return _DependencyManagement.instance;
30
+ }
31
+ /**
32
+ * Set the current resolution context (used during component instantiation)
33
+ */
34
+ setContext(selector, routerSelector) {
35
+ this.currentSelector = selector;
36
+ this.currentRouterSelector = routerSelector;
37
+ }
38
+ /**
39
+ * Clear the current resolution context
40
+ */
41
+ clearContext() {
42
+ this.currentSelector = void 0;
43
+ this.currentRouterSelector = void 0;
44
+ }
45
+ /**
46
+ * Get current component selector context
47
+ */
48
+ getCurrentSelector() {
49
+ return this.currentSelector;
50
+ }
51
+ /**
52
+ * Get current router selector context
53
+ */
54
+ getCurrentRouterSelector() {
55
+ return this.currentRouterSelector;
56
+ }
57
+ /**
58
+ * Generate a unique Symbol token for a class in a specific scope
59
+ */
60
+ getToken(className, scope) {
61
+ return /* @__PURE__ */ Symbol.for(`${scope}:${className}`);
62
+ }
63
+ /**
64
+ * Setup and register a provider in the root scope
65
+ */
66
+ setupRootContainer(Entity) {
67
+ const className = Entity.name;
68
+ if (!this.rootScope.has(className)) {
69
+ const scopedToken = this.getToken(className, "root");
70
+ this.rootScope.set(className, scopedToken);
71
+ this.rootClasses.set(className, Entity);
72
+ if (!this.container.isRegistered(scopedToken)) {
73
+ this.container.register(
74
+ scopedToken,
75
+ { useClass: Entity },
76
+ { lifecycle: Lifecycle.Singleton }
77
+ );
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * Get the root container (for backward compatibility)
83
+ */
84
+ getRootContainer() {
85
+ return this.container;
86
+ }
87
+ /**
88
+ * Legacy property accessor for backward compatibility
89
+ */
90
+ get root() {
91
+ return this.container;
92
+ }
93
+ /**
94
+ * Setup and register providers in a component scope
95
+ */
96
+ setupComponentContainer(selector, Providers = []) {
97
+ if (!this.componentScopes.has(selector)) {
98
+ this.componentScopes.set(selector, /* @__PURE__ */ new Map());
99
+ this.componentClasses.set(selector, /* @__PURE__ */ new Map());
100
+ }
101
+ const scopeMap = this.componentScopes.get(selector);
102
+ const classMap = this.componentClasses.get(selector);
103
+ if (!scopeMap || !classMap) {
104
+ throw new Error(
105
+ `Failed to create component scope for selector: ${selector}`
106
+ );
107
+ }
108
+ for (const Provider of Providers) {
109
+ const className = Provider.name;
110
+ if (!scopeMap.has(className)) {
111
+ const scopedToken = this.getToken(
112
+ className,
113
+ `component:${selector}`
114
+ );
115
+ scopeMap.set(className, scopedToken);
116
+ classMap.set(className, Provider);
117
+ if (!this.container.isRegistered(scopedToken)) {
118
+ this.container.register(
119
+ scopedToken,
120
+ { useClass: Provider },
121
+ { lifecycle: Lifecycle.Singleton }
122
+ );
123
+ }
124
+ }
125
+ }
126
+ }
127
+ /**
128
+ * Get a component-level container by selector (backward compatibility)
129
+ */
130
+ getComponentContainer(selector) {
131
+ if (!this.componentScopes.has(selector)) {
132
+ return void 0;
133
+ }
134
+ return this.container;
135
+ }
136
+ /**
137
+ * Legacy property accessor for backward compatibility
138
+ */
139
+ get component() {
140
+ const legacyMap = /* @__PURE__ */ new Map();
141
+ for (const selector of this.componentScopes.keys()) {
142
+ legacyMap.set(selector, this.container);
143
+ }
144
+ return legacyMap;
145
+ }
146
+ /**
147
+ * Setup and register providers in a router scope, tracking component membership
148
+ */
149
+ setupRouterContainer(Components, Providers, selector) {
150
+ if (!this.routerScopes.has(selector)) {
151
+ this.routerScopes.set(selector, /* @__PURE__ */ new Map());
152
+ this.routerClasses.set(selector, /* @__PURE__ */ new Map());
153
+ }
154
+ const scopeMap = this.routerScopes.get(selector);
155
+ const classMap = this.routerClasses.get(selector);
156
+ if (!scopeMap || !classMap) {
157
+ throw new Error(
158
+ `Failed to create router scope for selector: ${selector}`
159
+ );
160
+ }
161
+ for (const Component2 of Components) {
162
+ const componentName = typeof Component2 === "string" ? Component2 : Component2.name;
163
+ this.componentToRouter.set(componentName, selector);
164
+ }
165
+ for (const Provider of Providers) {
166
+ const className = Provider.name;
167
+ if (!scopeMap.has(className)) {
168
+ const scopedToken = this.getToken(
169
+ className,
170
+ `router:${selector}`
171
+ );
172
+ scopeMap.set(className, scopedToken);
173
+ classMap.set(className, Provider);
174
+ if (!this.container.isRegistered(scopedToken)) {
175
+ this.container.register(
176
+ scopedToken,
177
+ { useClass: Provider },
178
+ { lifecycle: Lifecycle.Singleton }
179
+ );
180
+ }
181
+ }
182
+ }
183
+ }
184
+ /**
185
+ * Get the router selector for a component (if registered in a router)
186
+ */
187
+ getRouterForComponent(componentName) {
188
+ return this.componentToRouter.get(componentName);
189
+ }
190
+ /**
191
+ * Fetch a provider from the router container associated with an entity (backward compatibility)
192
+ */
193
+ fetchFromRouterContainer(Entity) {
194
+ const routerSelector = this.getRouterForComponent(
195
+ Entity.name
196
+ );
197
+ if (routerSelector && this.routerScopes.has(routerSelector)) {
198
+ return this.container;
199
+ }
200
+ return void 0;
201
+ }
202
+ /**
203
+ * Get a router-level container by selector (backward compatibility)
204
+ */
205
+ getRouterContainer(selector) {
206
+ if (!this.routerScopes.has(selector)) {
207
+ return void 0;
208
+ }
209
+ return this.container;
210
+ }
211
+ /**
212
+ * Legacy property accessor for backward compatibility
213
+ */
214
+ get router() {
215
+ const legacyMap = /* @__PURE__ */ new Map();
216
+ for (const selector of this.routerScopes.keys()) {
217
+ legacyMap.set(selector, this.container);
218
+ }
219
+ return legacyMap;
220
+ }
221
+ /**
222
+ * Check if a class is a MobX store by looking for MobX symbols
223
+ */
224
+ isMobxStore(instance) {
225
+ const mobxSymbol = "mobx-stored-annotations";
226
+ const symbols = Object.getOwnPropertySymbols(instance);
227
+ return symbols.some((s) => s.description === mobxSymbol);
228
+ }
229
+ /**
230
+ * Resolve a dependency with strict scope isolation:
231
+ * 1. Component scope (if component explicitly registered the provider)
232
+ * 2. Router scope (ONLY if component is part of that router's components array)
233
+ * 3. Root scope (for @Injectable({ providedIn: 'root' }) services)
234
+ *
235
+ * Scope override behavior:
236
+ * - If a root service is re-registered at router/component level, that scope gets a NEW instance
237
+ * - Router-scoped services are ONLY accessible to components within that router
238
+ * - Parent components cannot access child router services
239
+ *
240
+ * Returns undefined if no provider is found in accessible scopes
241
+ */
242
+ resolve(className, componentSelector, routerSelector, componentClassName) {
243
+ if (className === "DependencyManagement") {
244
+ return this.container.resolve("DependencyManagement");
245
+ }
246
+ if (componentSelector) {
247
+ const componentScope = this.componentScopes.get(componentSelector);
248
+ const componentToken = componentScope?.get(className);
249
+ if (componentToken && this.container.isRegistered(componentToken)) {
250
+ return this.container.resolve(componentToken);
251
+ }
252
+ }
253
+ if (routerSelector) {
254
+ const routerScope = this.routerScopes.get(routerSelector);
255
+ const routerToken = routerScope?.get(className);
256
+ if (routerToken && this.container.isRegistered(routerToken)) {
257
+ return this.container.resolve(routerToken);
258
+ }
259
+ }
260
+ const parentRouterSelector = componentClassName ? this.getRouterForComponent(componentClassName) : void 0;
261
+ if (parentRouterSelector && parentRouterSelector !== routerSelector) {
262
+ const parentRouterScope = this.routerScopes.get(parentRouterSelector);
263
+ const parentRouterToken = parentRouterScope?.get(className);
264
+ if (parentRouterToken && this.container.isRegistered(parentRouterToken)) {
265
+ return this.container.resolve(parentRouterToken);
266
+ }
267
+ }
268
+ const rootToken = this.rootScope.get(className);
269
+ if (rootToken && this.container.isRegistered(rootToken)) {
270
+ return this.container.resolve(rootToken);
271
+ }
272
+ return void 0;
273
+ }
274
+ /**
275
+ * Convenience method for resolving dependencies using current context.
276
+ * Use this in component constructors when DependencyManagement is injected.
277
+ *
278
+ * @example
279
+ * constructor(private dm: DependencyManagement) {
280
+ * this.myService = dm.get<MyService>('MyService');
281
+ * }
282
+ */
283
+ get(className) {
284
+ return this.resolve(
285
+ className,
286
+ this.currentSelector,
287
+ this.currentRouterSelector
288
+ );
289
+ }
290
+ /**
291
+ * Resolve a dependency from component, router, or root scope (backward compatibility)
292
+ */
293
+ resolveFromScopes(EntityName, componentContainer, routerContainer) {
294
+ let componentSelector;
295
+ let routerSelector;
296
+ if (componentContainer) {
297
+ for (const [selector, _scopeMap] of this.componentScopes.entries()) {
298
+ componentSelector = selector;
299
+ break;
300
+ }
301
+ }
302
+ if (routerContainer) {
303
+ for (const [selector, _scopeMap] of this.routerScopes.entries()) {
304
+ routerSelector = selector;
305
+ break;
306
+ }
307
+ }
308
+ return this.resolve(EntityName, componentSelector, routerSelector);
309
+ }
310
+ /**
311
+ * Re-register all providers (helper for reset operations)
312
+ */
313
+ reregisterAll() {
314
+ for (const [className, token] of this.rootScope.entries()) {
315
+ const Provider = this.rootClasses.get(className);
316
+ if (Provider) {
317
+ this.container.register(
318
+ token,
319
+ { useClass: Provider },
320
+ { lifecycle: Lifecycle.Singleton }
321
+ );
322
+ }
323
+ }
324
+ for (const [selector, routerScope] of this.routerScopes.entries()) {
325
+ const routerClassMap = this.routerClasses.get(selector);
326
+ if (routerClassMap) {
327
+ for (const [className, token] of routerScope.entries()) {
328
+ const Provider = routerClassMap.get(className);
329
+ if (Provider) {
330
+ this.container.register(
331
+ token,
332
+ { useClass: Provider },
333
+ { lifecycle: Lifecycle.Singleton }
334
+ );
335
+ }
336
+ }
337
+ }
338
+ }
339
+ for (const [selector, componentScope] of this.componentScopes.entries()) {
340
+ const componentClassMap = this.componentClasses.get(selector);
341
+ if (componentClassMap) {
342
+ for (const [className, token] of componentScope.entries()) {
343
+ const Provider = componentClassMap.get(className);
344
+ if (Provider) {
345
+ this.container.register(
346
+ token,
347
+ { useClass: Provider },
348
+ { lifecycle: Lifecycle.Singleton }
349
+ );
350
+ }
351
+ }
352
+ }
353
+ }
354
+ }
355
+ /**
356
+ * Reset all instances in a specific scope
357
+ * Creates fresh container and re-registers all providers
358
+ * Note: Due to tsyringe limitations, this resets ALL scopes but is still useful for cleanup
359
+ */
360
+ resetScope(_scope, _selector) {
361
+ this.container.reset();
362
+ this.container = tsyringe.createChildContainer();
363
+ this.reregisterAll();
364
+ }
365
+ /**
366
+ * Reset a specific class across all scopes
367
+ * Creates fresh container and re-registers all providers
368
+ * Note: Due to tsyringe limitations, this resets ALL instances
369
+ */
370
+ resetClass(_className) {
371
+ this.container.reset();
372
+ this.container = tsyringe.createChildContainer();
373
+ this.reregisterAll();
374
+ }
375
+ /**
376
+ * Reset all instances in all scopes
377
+ * This clears all cached singletons but keeps registrations
378
+ */
379
+ resetAll() {
380
+ this.container.clearInstances();
381
+ }
382
+ };
383
+
384
+ // src/decorators/Component.ts
385
+ import React from "react";
386
+ import { observer } from "mobx-react";
387
+ import { injectable } from "tsyringe";
388
+ var componentRegistry = /* @__PURE__ */ new Map();
389
+ var componentReverseRegistry = /* @__PURE__ */ new Map();
390
+ function Component(params) {
391
+ const decorator = function(Entity) {
392
+ injectable()(Entity);
393
+ class ComponentWrapper extends React.Component {
394
+ constructor(props) {
395
+ super(props);
396
+ this.entityInstance = null;
397
+ const initialState = {};
398
+ this.state = initialState;
399
+ this.dependencyManagement = DependencyManagement.getInstance();
400
+ this.dependencyManagement.setupComponentContainer(params.selector, [
401
+ ...params.providers || [],
402
+ Entity
403
+ ]);
404
+ const componentContainer = this.dependencyManagement.getComponentContainer(params.selector);
405
+ const routerSelector = this.dependencyManagement.getRouterForComponent(Entity.name);
406
+ const self = this;
407
+ const controller = {
408
+ props,
409
+ get state() {
410
+ return self.state;
411
+ },
412
+ setState: (state) => {
413
+ if (typeof state === "function") {
414
+ this.setState((prevState) => {
415
+ const newState = state(prevState);
416
+ return newState;
417
+ });
418
+ } else {
419
+ this.setState((prevState) => {
420
+ const newState = {
421
+ ...prevState,
422
+ ...state
423
+ };
424
+ return newState;
425
+ });
426
+ }
427
+ },
428
+ forceUpdate: this.forceUpdate.bind(this)
429
+ };
430
+ componentContainer?.register("Controller", { useValue: controller });
431
+ const paramTypes = Reflect.getMetadata(
432
+ "design:paramtypes",
433
+ Entity
434
+ );
435
+ const constructorArgs = [];
436
+ if (paramTypes && paramTypes.length > 0) {
437
+ for (const ParamType of paramTypes) {
438
+ let dependency = this.dependencyManagement.resolve(
439
+ ParamType.name,
440
+ params.selector,
441
+ routerSelector,
442
+ Entity.name
443
+ );
444
+ if (dependency === void 0 && ParamType.name === "Object") {
445
+ dependency = componentContainer?.resolve("Controller");
446
+ }
447
+ constructorArgs.push(dependency);
448
+ }
449
+ }
450
+ this.entityInstance = // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
451
+ new Entity(...constructorArgs) ?? null;
452
+ if (this.entityInstance?.state !== void 0 && this.entityInstance?.state !== null) {
453
+ const entityState = Object.assign(
454
+ {},
455
+ this.entityInstance.state
456
+ );
457
+ Object.assign(this.state, entityState);
458
+ }
459
+ if (this.entityInstance) {
460
+ const prototype = Object.getPrototypeOf(
461
+ this.entityInstance
462
+ );
463
+ Object.getOwnPropertyNames(prototype).forEach((key) => {
464
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
465
+ if (key !== "constructor" && descriptor && typeof descriptor.value === "function") {
466
+ this.entityInstance[key] = descriptor.value.bind(this.entityInstance);
467
+ }
468
+ });
469
+ if ("state" in this.entityInstance) {
470
+ Object.defineProperty(this.entityInstance, "state", {
471
+ get: () => controller.state,
472
+ configurable: true,
473
+ enumerable: true
474
+ });
475
+ }
476
+ }
477
+ }
478
+ componentDidMount() {
479
+ if (this.entityInstance && typeof this.entityInstance.componentDidMount === "function") {
480
+ this.entityInstance.componentDidMount.call(this.entityInstance);
481
+ }
482
+ }
483
+ componentDidUpdate(prevProps, prevState) {
484
+ if (this.entityInstance && typeof this.entityInstance.componentDidUpdate === "function") {
485
+ this.entityInstance.componentDidUpdate.call(
486
+ this.entityInstance,
487
+ prevProps,
488
+ prevState
489
+ );
490
+ }
491
+ }
492
+ componentWillUnmount() {
493
+ if (this.entityInstance && typeof this.entityInstance.componentWillUnmount === "function") {
494
+ this.entityInstance.componentWillUnmount.call(this.entityInstance);
495
+ }
496
+ }
497
+ render() {
498
+ if (!this.entityInstance) {
499
+ return null;
500
+ }
501
+ return this.entityInstance.render.call(this.entityInstance);
502
+ }
503
+ }
504
+ const wrappedComponent = observer(ComponentWrapper);
505
+ const reactComponent = wrappedComponent;
506
+ componentRegistry.set(Entity.name, reactComponent);
507
+ componentReverseRegistry.set(reactComponent, Entity.name);
508
+ return Entity;
509
+ };
510
+ decorator.$provider = (Entity) => {
511
+ const component = componentRegistry.get(Entity.name);
512
+ if (!component) {
513
+ throw new Error(
514
+ `Component ${Entity.name} not found. Make sure to apply @Component decorator first.`
515
+ );
516
+ }
517
+ return component;
518
+ };
519
+ return decorator;
520
+ }
521
+ function getComponentClassName(component) {
522
+ return componentReverseRegistry.get(component);
523
+ }
524
+ Component.$provider = (Entity) => {
525
+ const component = componentRegistry.get(Entity.name);
526
+ if (!component) {
527
+ throw new Error(
528
+ `Component ${Entity.name} not found. Make sure to apply @Component decorator first.`
529
+ );
530
+ }
531
+ return component;
532
+ };
533
+
534
+ // src/decorators/Injectable.ts
535
+ import { injectable as injectable2 } from "tsyringe";
536
+ function Injectable(params) {
537
+ return function(Entity) {
538
+ injectable2()(Entity);
539
+ if (params?.providedIn === "root") {
540
+ const dependencyManagement = DependencyManagement.getInstance();
541
+ dependencyManagement.setupRootContainer(Entity);
542
+ }
543
+ return Entity;
544
+ };
545
+ }
546
+
547
+ // src/decorators/Router.ts
548
+ import React2 from "react";
549
+ import { observer as observer2 } from "mobx-react";
550
+ import { injectable as injectable3 } from "tsyringe";
551
+ var routerRegistry = /* @__PURE__ */ new Map();
552
+ var routerReverseRegistry = /* @__PURE__ */ new Map();
553
+ function getRouterClassName(router) {
554
+ return routerReverseRegistry.get(router);
555
+ }
556
+ function Router(params) {
557
+ const decorator = function(Entity) {
558
+ injectable3()(Entity);
559
+ const dependencyManagement = DependencyManagement.getInstance();
560
+ const componentClassNames = params.components.map((comp) => {
561
+ const componentClassName = getComponentClassName(
562
+ comp
563
+ );
564
+ if (componentClassName) {
565
+ return componentClassName;
566
+ }
567
+ const routerClassName = getRouterClassName(
568
+ comp
569
+ );
570
+ if (routerClassName) {
571
+ return routerClassName;
572
+ }
573
+ const classComp = comp;
574
+ return classComp.name || void 0;
575
+ }).filter((name) => name !== void 0);
576
+ dependencyManagement.setupRouterContainer(
577
+ componentClassNames,
578
+ [...params.providers || [], Entity],
579
+ params.selector
580
+ );
581
+ class RouterWrapper extends React2.Component {
582
+ constructor(props) {
583
+ super(props);
584
+ this.entityInstance = null;
585
+ const initialState = {};
586
+ this.state = initialState;
587
+ this.dependencyManagement = DependencyManagement.getInstance();
588
+ const routerContainerInstance = this.dependencyManagement.getRouterContainer(params.selector);
589
+ const wrapperInstance = this;
590
+ const controller = {
591
+ props,
592
+ get state() {
593
+ return wrapperInstance.state;
594
+ },
595
+ setState: (state) => {
596
+ if (typeof state === "function") {
597
+ this.setState((prevState) => {
598
+ const newState = state(prevState);
599
+ if (this.entityInstance?.state) {
600
+ Object.assign(this.entityInstance.state, newState);
601
+ }
602
+ return newState;
603
+ });
604
+ } else {
605
+ this.setState((prevState) => {
606
+ const newState = {
607
+ ...prevState,
608
+ ...state
609
+ };
610
+ if (this.entityInstance?.state) {
611
+ Object.assign(this.entityInstance.state, newState);
612
+ }
613
+ return newState;
614
+ });
615
+ }
616
+ },
617
+ forceUpdate: this.forceUpdate.bind(this)
618
+ };
619
+ routerContainerInstance?.register("Controller", { useValue: controller });
620
+ const paramTypes = Reflect.getMetadata(
621
+ "design:paramtypes",
622
+ Entity
623
+ );
624
+ const constructorArgs = [];
625
+ if (paramTypes && paramTypes.length > 0) {
626
+ for (const ParamType of paramTypes) {
627
+ let dependency = this.dependencyManagement.resolve(
628
+ ParamType.name,
629
+ void 0,
630
+ // No component selector - this is a router
631
+ params.selector,
632
+ // Own router scope
633
+ Entity.name
634
+ // Pass class name to find parent router if needed
635
+ );
636
+ if (dependency === void 0 && ParamType.name === "Object") {
637
+ dependency = routerContainerInstance?.resolve("Controller");
638
+ }
639
+ constructorArgs.push(dependency);
640
+ }
641
+ }
642
+ this.entityInstance = // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
643
+ new Entity(...constructorArgs) ?? null;
644
+ if (this.entityInstance?.state !== void 0 && this.entityInstance?.state !== null) {
645
+ const entityState = Object.assign(
646
+ {},
647
+ this.entityInstance.state
648
+ );
649
+ Object.assign(this.state, entityState);
650
+ }
651
+ if (this.entityInstance) {
652
+ const prototype = Object.getPrototypeOf(
653
+ this.entityInstance
654
+ );
655
+ Object.getOwnPropertyNames(prototype).forEach((key) => {
656
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
657
+ if (key !== "constructor" && descriptor && typeof descriptor.value === "function") {
658
+ this.entityInstance[key] = descriptor.value.bind(this.entityInstance);
659
+ }
660
+ });
661
+ if ("state" in this.entityInstance) {
662
+ Object.defineProperty(this.entityInstance, "state", {
663
+ get: () => controller.state,
664
+ configurable: true,
665
+ enumerable: true
666
+ });
667
+ }
668
+ }
669
+ }
670
+ componentDidMount() {
671
+ if (this.entityInstance && typeof this.entityInstance.componentDidMount === "function") {
672
+ this.entityInstance.componentDidMount.call(this.entityInstance);
673
+ }
674
+ }
675
+ componentDidUpdate(prevProps, prevState) {
676
+ if (this.entityInstance && typeof this.entityInstance.componentDidUpdate === "function") {
677
+ this.entityInstance.componentDidUpdate.call(
678
+ this.entityInstance,
679
+ prevProps,
680
+ prevState
681
+ );
682
+ }
683
+ }
684
+ componentWillUnmount() {
685
+ if (this.entityInstance && typeof this.entityInstance.componentWillUnmount === "function") {
686
+ this.entityInstance.componentWillUnmount.call(this.entityInstance);
687
+ }
688
+ }
689
+ render() {
690
+ if (!this.entityInstance) {
691
+ return null;
692
+ }
693
+ return this.entityInstance.render.call(this.entityInstance);
694
+ }
695
+ }
696
+ const wrappedComponent = observer2(RouterWrapper);
697
+ const reactComponent = wrappedComponent;
698
+ routerRegistry.set(Entity.name, reactComponent);
699
+ routerReverseRegistry.set(reactComponent, Entity.name);
700
+ return Entity;
701
+ };
702
+ return decorator;
703
+ }
704
+ Router.$provider = (Entity) => {
705
+ const component = routerRegistry.get(Entity.name);
706
+ if (!component) {
707
+ throw new Error(
708
+ `Router ${Entity.name} not found. Make sure to apply @Router decorator first.`
709
+ );
710
+ }
711
+ return component;
712
+ };
713
+
714
+ // src/index.ts
715
+ function resetScope(_scope, _selector) {
716
+ DependencyManagement.getInstance().resetScope(_scope, _selector);
717
+ }
718
+ function resetClass(_className) {
719
+ DependencyManagement.getInstance().resetClass(_className);
720
+ }
721
+ function resetAll() {
722
+ DependencyManagement.getInstance().resetAll();
723
+ }
724
+ export {
725
+ Component,
726
+ Injectable,
727
+ Router,
728
+ resetAll,
729
+ resetClass,
730
+ resetScope
731
+ };
732
+ //# sourceMappingURL=index.mjs.map