@logixjs/react 0.1.1 → 1.0.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/Hooks.cjs +345 -142
- package/dist/Hooks.js +3 -3
- package/dist/ModuleScope.cjs +474 -187
- package/dist/ModuleScope.js +4 -4
- package/dist/Platform.cjs +1 -4
- package/dist/Platform.d.cts +1 -2
- package/dist/Platform.d.ts +1 -2
- package/dist/Platform.js +1 -1
- package/dist/ReactPlatform.cjs +395 -111
- package/dist/ReactPlatform.js +5 -5
- package/dist/RuntimeProvider.cjs +254 -50
- package/dist/RuntimeProvider.js +2 -2
- package/dist/{chunk-WOTNVLCD.js → chunk-6NLXTHZ7.js} +8 -8
- package/dist/{chunk-G2LX7WWQ.js → chunk-E3ZXST5F.js} +129 -49
- package/dist/{chunk-JC3R6GII.js → chunk-KYWW4KMQ.js} +3 -3
- package/dist/{chunk-2WFULYPJ.js → chunk-L7KTYBXN.js} +155 -32
- package/dist/{chunk-ZANGOPUQ.js → chunk-NKYV44OG.js} +1 -4
- package/dist/{chunk-STTE4SOJ.js → chunk-SDQF3WRT.js} +6 -3
- package/dist/{chunk-2M6MDNVT.js → chunk-XSGDBJXD.js} +100 -19
- package/dist/index.cjs +435 -151
- package/dist/index.js +7 -7
- package/package.json +9 -4
package/dist/Hooks.cjs
CHANGED
|
@@ -125,14 +125,11 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
|
|
|
125
125
|
const newScope = import_effect.Effect.runSync(import_effect.Scope.make());
|
|
126
126
|
const buildEffect = import_effect.Effect.gen(function* () {
|
|
127
127
|
const context = yield* import_effect.Layer.buildWithScope(layer, newScope);
|
|
128
|
-
const applyEnv = (effect) => import_effect.Effect.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
);
|
|
132
|
-
const loggers = yield* applyEnv(import_effect.FiberRef.get(import_effect.FiberRef.currentLoggers));
|
|
133
|
-
const logLevel = yield* applyEnv(import_effect.FiberRef.get(import_effect.FiberRef.currentLogLevel));
|
|
128
|
+
const applyEnv = (effect) => import_effect.Scope.provide(newScope)(import_effect.Effect.provideServices(effect, context));
|
|
129
|
+
const loggers = yield* applyEnv(import_effect.Effect.service(import_effect.Logger.CurrentLoggers)).pipe(import_effect.Effect.orDie);
|
|
130
|
+
const logLevel = yield* applyEnv(import_effect.Effect.service(import_effect.References.MinimumLogLevel)).pipe(import_effect.Effect.orDie);
|
|
134
131
|
const debugSinks = yield* applyEnv(
|
|
135
|
-
import_effect.
|
|
132
|
+
import_effect.Effect.service(Logix.Debug.internal.currentDebugSinks).pipe(import_effect.Effect.orDie)
|
|
136
133
|
);
|
|
137
134
|
return { context, loggers, logLevel, debugSinks };
|
|
138
135
|
});
|
|
@@ -177,7 +174,7 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
|
|
|
177
174
|
const cause = import_effect.Cause.die(error);
|
|
178
175
|
runtime.runFork(
|
|
179
176
|
onError(cause, { source: "provider", phase: "provider.layer.build" }).pipe(
|
|
180
|
-
import_effect.Effect.
|
|
177
|
+
import_effect.Effect.catchCause(() => import_effect.Effect.void)
|
|
181
178
|
)
|
|
182
179
|
);
|
|
183
180
|
}
|
|
@@ -215,18 +212,11 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
|
|
|
215
212
|
if (contexts.length === 0 && scopes.length === 0 && loggerSets.length === 0 && logLevels.length === 0 && debugSinks.length === 0) {
|
|
216
213
|
return runtime;
|
|
217
214
|
}
|
|
218
|
-
const applyContexts = (effect) => (
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
acc,
|
|
224
|
-
(parent) => import_effect.Context.merge(parent, ctx)
|
|
225
|
-
),
|
|
226
|
-
scopes.reduceRight(
|
|
227
|
-
(acc, scope) => import_effect.Scope.extend(acc, scope),
|
|
228
|
-
effect
|
|
229
|
-
)
|
|
215
|
+
const applyContexts = (effect) => contexts.reduceRight(
|
|
216
|
+
(acc, ctx) => import_effect.Effect.provideServices(acc, ctx),
|
|
217
|
+
scopes.reduceRight(
|
|
218
|
+
(acc, scope) => import_effect.Scope.provide(scope)(acc),
|
|
219
|
+
effect
|
|
230
220
|
)
|
|
231
221
|
);
|
|
232
222
|
const applyLoggers = (effect) => {
|
|
@@ -235,16 +225,13 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
|
|
|
235
225
|
const sinks = debugSinks.length > 0 ? debugSinks[debugSinks.length - 1] : null;
|
|
236
226
|
let result = effect;
|
|
237
227
|
if (last) {
|
|
238
|
-
result = import_effect.Effect.
|
|
228
|
+
result = import_effect.Effect.provideService(result, import_effect.Logger.CurrentLoggers, last);
|
|
239
229
|
}
|
|
240
230
|
if (logLevel) {
|
|
241
|
-
result = import_effect.Effect.
|
|
231
|
+
result = import_effect.Effect.provideService(result, import_effect.References.MinimumLogLevel, logLevel);
|
|
242
232
|
}
|
|
243
233
|
if (sinks && sinks.length > 0) {
|
|
244
|
-
result = import_effect.Effect.
|
|
245
|
-
Logix.Debug.internal.currentDebugSinks,
|
|
246
|
-
sinks
|
|
247
|
-
)(result);
|
|
234
|
+
result = import_effect.Effect.provideService(result, Logix.Debug.internal.currentDebugSinks, sinks);
|
|
248
235
|
}
|
|
249
236
|
return result;
|
|
250
237
|
};
|
|
@@ -336,13 +323,13 @@ function useRuntime(options) {
|
|
|
336
323
|
|
|
337
324
|
// src/internal/hooks/useModule.ts
|
|
338
325
|
var import_react7 = __toESM(require("react"), 1);
|
|
339
|
-
var
|
|
340
|
-
var
|
|
326
|
+
var Logix9 = __toESM(require("@logixjs/core"), 1);
|
|
327
|
+
var import_effect8 = require("effect");
|
|
341
328
|
|
|
342
329
|
// src/internal/hooks/useModuleRuntime.ts
|
|
343
330
|
var import_react4 = require("react");
|
|
344
|
-
var
|
|
345
|
-
var
|
|
331
|
+
var Logix5 = __toESM(require("@logixjs/core"), 1);
|
|
332
|
+
var import_effect6 = require("effect");
|
|
346
333
|
|
|
347
334
|
// src/internal/store/ModuleRef.ts
|
|
348
335
|
var isModuleRef = (value) => typeof value === "object" && value !== null && "runtime" in value && "actions" in value && "dispatch" in value;
|
|
@@ -433,27 +420,41 @@ var applyHandleExtend = (tag, runtime, base) => {
|
|
|
433
420
|
return { ...base, ...next };
|
|
434
421
|
};
|
|
435
422
|
|
|
423
|
+
// src/internal/provider/runtimeDebugBridge.ts
|
|
424
|
+
var import_effect3 = require("effect");
|
|
425
|
+
var Logix2 = __toESM(require("@logixjs/core"), 1);
|
|
426
|
+
var readRuntimeDiagnosticsLevel = (runtime) => {
|
|
427
|
+
try {
|
|
428
|
+
return runtime.runSync(import_effect3.Effect.service(Logix2.Debug.internal.currentDiagnosticsLevel).pipe(import_effect3.Effect.orDie));
|
|
429
|
+
} catch {
|
|
430
|
+
return (0, import_Env.isDevEnv)() ? "light" : "off";
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
var emitRuntimeDebugEventBestEffort = (runtime, event) => {
|
|
434
|
+
runtime.runFork(event);
|
|
435
|
+
};
|
|
436
|
+
|
|
436
437
|
// src/internal/store/ModuleCache.ts
|
|
437
|
-
var
|
|
438
|
-
var
|
|
438
|
+
var Logix4 = __toESM(require("@logixjs/core"), 1);
|
|
439
|
+
var import_effect5 = require("effect");
|
|
439
440
|
|
|
440
441
|
// src/internal/store/perfWorkloads.ts
|
|
441
|
-
var
|
|
442
|
-
var
|
|
443
|
-
var PerfCounterStateSchema =
|
|
444
|
-
value:
|
|
442
|
+
var Logix3 = __toESM(require("@logixjs/core"), 1);
|
|
443
|
+
var import_effect4 = require("effect");
|
|
444
|
+
var PerfCounterStateSchema = import_effect4.Schema.Struct({
|
|
445
|
+
value: import_effect4.Schema.Number
|
|
445
446
|
});
|
|
446
447
|
var PerfCounterActions = {
|
|
447
|
-
inc:
|
|
448
|
+
inc: import_effect4.Schema.Void
|
|
448
449
|
};
|
|
449
|
-
var PerfListScopeRowSchema =
|
|
450
|
-
id:
|
|
451
|
-
warehouseId:
|
|
450
|
+
var PerfListScopeRowSchema = import_effect4.Schema.Struct({
|
|
451
|
+
id: import_effect4.Schema.String,
|
|
452
|
+
warehouseId: import_effect4.Schema.String
|
|
452
453
|
});
|
|
453
|
-
var PerfListScopeStateSchema =
|
|
454
|
-
items:
|
|
455
|
-
digest:
|
|
456
|
-
errors:
|
|
454
|
+
var PerfListScopeStateSchema = import_effect4.Schema.Struct({
|
|
455
|
+
items: import_effect4.Schema.Array(PerfListScopeRowSchema),
|
|
456
|
+
digest: import_effect4.Schema.String,
|
|
457
|
+
errors: import_effect4.Schema.Any
|
|
457
458
|
});
|
|
458
459
|
var GLOBAL_YIELD_BUDGET_MEMORY_KEY = "__LOGIX_REACT_YIELD_BUDGET_MEMORY__";
|
|
459
460
|
var getGlobalYieldBudgetMemory = () => {
|
|
@@ -548,20 +549,20 @@ ${message}`;
|
|
|
548
549
|
console.debug(label, message);
|
|
549
550
|
};
|
|
550
551
|
var causeToUnknown = (cause) => {
|
|
551
|
-
const failure =
|
|
552
|
+
const failure = import_effect5.Option.getOrUndefined(import_effect5.Cause.findErrorOption(cause));
|
|
552
553
|
if (failure !== void 0) return failure;
|
|
553
|
-
const defect =
|
|
554
|
+
const defect = cause.reasons.filter(import_effect5.Cause.isDieReason).map((reason) => reason.defect)[0];
|
|
554
555
|
if (defect !== void 0) return defect;
|
|
555
556
|
return cause;
|
|
556
557
|
};
|
|
557
558
|
var yieldEffect = (strategy) => {
|
|
558
559
|
switch (strategy) {
|
|
559
560
|
case "none":
|
|
560
|
-
return
|
|
561
|
+
return import_effect5.Effect.void;
|
|
561
562
|
case "microtask":
|
|
562
|
-
return
|
|
563
|
+
return import_effect5.Effect.yieldNow;
|
|
563
564
|
case "macrotask":
|
|
564
|
-
return
|
|
565
|
+
return import_effect5.Effect.promise(
|
|
565
566
|
() => new Promise((resolve) => {
|
|
566
567
|
setTimeout(resolve, 0);
|
|
567
568
|
})
|
|
@@ -609,11 +610,11 @@ var ModuleCache = class {
|
|
|
609
610
|
this.scheduleGC(key, current);
|
|
610
611
|
return;
|
|
611
612
|
}
|
|
612
|
-
void this.runtime.runPromise(
|
|
613
|
+
void this.runtime.runPromise(import_effect5.Scope.close(current.scope, import_effect5.Exit.void)).catch((error) => {
|
|
613
614
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", error);
|
|
614
615
|
});
|
|
615
616
|
void this.runtime.runPromise(
|
|
616
|
-
|
|
617
|
+
Logix4.Debug.record({
|
|
617
618
|
type: "trace:react.module-instance",
|
|
618
619
|
moduleId: current.ownerId,
|
|
619
620
|
instanceId: current.value?.instanceId,
|
|
@@ -649,9 +650,70 @@ var ModuleCache = class {
|
|
|
649
650
|
}
|
|
650
651
|
return existing.value;
|
|
651
652
|
}
|
|
652
|
-
const scope =
|
|
653
|
+
const scope = import_effect5.Effect.runSync(import_effect5.Scope.make());
|
|
653
654
|
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
654
655
|
const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
|
|
656
|
+
const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
|
|
657
|
+
const shouldTryOptimisticSync = options?.policyMode === "suspend" && optimisticSyncBudgetMs > 0;
|
|
658
|
+
if (shouldTryOptimisticSync) {
|
|
659
|
+
const startedAt2 = performance.now();
|
|
660
|
+
try {
|
|
661
|
+
const value = this.runtime.runSync(factory(scope));
|
|
662
|
+
const durationMs = performance.now() - startedAt2;
|
|
663
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
664
|
+
const entry2 = {
|
|
665
|
+
scope,
|
|
666
|
+
status: "success",
|
|
667
|
+
promise: Promise.resolve(value),
|
|
668
|
+
value,
|
|
669
|
+
refCount: 0,
|
|
670
|
+
preloadRefCount: 0,
|
|
671
|
+
gcTime: gcTime ?? this.gcDelayMs,
|
|
672
|
+
ownerId,
|
|
673
|
+
createdBy: "read",
|
|
674
|
+
workloadKey,
|
|
675
|
+
yieldStrategy: "none"
|
|
676
|
+
};
|
|
677
|
+
this.scheduleGC(key, entry2);
|
|
678
|
+
this.entries.set(key, entry2);
|
|
679
|
+
if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
|
|
680
|
+
void this.runtime.runPromise(
|
|
681
|
+
Logix4.Debug.record({
|
|
682
|
+
type: "trace:react.module.init",
|
|
683
|
+
moduleId: ownerId,
|
|
684
|
+
instanceId: value.instanceId,
|
|
685
|
+
data: {
|
|
686
|
+
mode: "suspend",
|
|
687
|
+
key,
|
|
688
|
+
durationMs: Math.round(durationMs * 100) / 100,
|
|
689
|
+
yieldStrategy: "none",
|
|
690
|
+
fastPath: "sync"
|
|
691
|
+
}
|
|
692
|
+
})
|
|
693
|
+
).catch((error) => {
|
|
694
|
+
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
695
|
+
});
|
|
696
|
+
void this.runtime.runPromise(
|
|
697
|
+
Logix4.Debug.record({
|
|
698
|
+
type: "trace:react.module-instance",
|
|
699
|
+
moduleId: ownerId,
|
|
700
|
+
instanceId: value.instanceId,
|
|
701
|
+
data: {
|
|
702
|
+
event: "attach",
|
|
703
|
+
key,
|
|
704
|
+
mode: "suspend",
|
|
705
|
+
gcTime: entry2.gcTime,
|
|
706
|
+
fastPath: "sync"
|
|
707
|
+
}
|
|
708
|
+
})
|
|
709
|
+
).catch((error) => {
|
|
710
|
+
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
return value;
|
|
714
|
+
} catch {
|
|
715
|
+
}
|
|
716
|
+
}
|
|
655
717
|
const entry = {
|
|
656
718
|
scope,
|
|
657
719
|
status: "pending",
|
|
@@ -667,11 +729,11 @@ var ModuleCache = class {
|
|
|
667
729
|
};
|
|
668
730
|
this.scheduleGC(key, entry);
|
|
669
731
|
const startedAt = performance.now();
|
|
670
|
-
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(
|
|
732
|
+
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect5.Effect.flatMap(() => factory(scope)));
|
|
671
733
|
const fiber = this.runtime.runFork(buildEffect);
|
|
672
734
|
entry.fiber = fiber;
|
|
673
|
-
const promise = this.runtime.runPromise(
|
|
674
|
-
if (
|
|
735
|
+
const promise = this.runtime.runPromise(import_effect5.Fiber.await(fiber)).then((exit) => {
|
|
736
|
+
if (import_effect5.Exit.isSuccess(exit)) return exit.value;
|
|
675
737
|
throw causeToUnknown(exit.cause);
|
|
676
738
|
});
|
|
677
739
|
promise.then((value) => {
|
|
@@ -679,9 +741,9 @@ var ModuleCache = class {
|
|
|
679
741
|
entry.value = value;
|
|
680
742
|
const durationMs = performance.now() - startedAt;
|
|
681
743
|
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
682
|
-
if ((0, import_Env.isDevEnv)() ||
|
|
744
|
+
if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
|
|
683
745
|
void this.runtime.runPromise(
|
|
684
|
-
|
|
746
|
+
Logix4.Debug.record({
|
|
685
747
|
type: "trace:react.module.init",
|
|
686
748
|
moduleId: ownerId,
|
|
687
749
|
instanceId: value.instanceId,
|
|
@@ -698,7 +760,7 @@ var ModuleCache = class {
|
|
|
698
760
|
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
699
761
|
});
|
|
700
762
|
void this.runtime.runPromise(
|
|
701
|
-
|
|
763
|
+
Logix4.Debug.record({
|
|
702
764
|
type: "trace:react.module-instance",
|
|
703
765
|
moduleId: ownerId,
|
|
704
766
|
instanceId: value.instanceId,
|
|
@@ -728,7 +790,7 @@ var ModuleCache = class {
|
|
|
728
790
|
workloadKey,
|
|
729
791
|
durationMs: performance.now() - startedAt
|
|
730
792
|
});
|
|
731
|
-
void this.runtime.runPromise(
|
|
793
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
732
794
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
733
795
|
});
|
|
734
796
|
throw error;
|
|
@@ -760,7 +822,7 @@ var ModuleCache = class {
|
|
|
760
822
|
}
|
|
761
823
|
return existing.value;
|
|
762
824
|
}
|
|
763
|
-
const scope = this.runtime.runSync(
|
|
825
|
+
const scope = this.runtime.runSync(import_effect5.Scope.make());
|
|
764
826
|
const startedAt = performance.now();
|
|
765
827
|
try {
|
|
766
828
|
const value = this.runtime.runSync(factory(scope));
|
|
@@ -808,9 +870,9 @@ var ModuleCache = class {
|
|
|
808
870
|
}
|
|
809
871
|
}
|
|
810
872
|
}
|
|
811
|
-
if ((0, import_Env.isDevEnv)() ||
|
|
873
|
+
if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
|
|
812
874
|
void this.runtime.runPromise(
|
|
813
|
-
|
|
875
|
+
Logix4.Debug.record({
|
|
814
876
|
type: "trace:react.module.init",
|
|
815
877
|
moduleId: ownerId,
|
|
816
878
|
instanceId: value.instanceId,
|
|
@@ -825,7 +887,7 @@ var ModuleCache = class {
|
|
|
825
887
|
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
826
888
|
});
|
|
827
889
|
void this.runtime.runPromise(
|
|
828
|
-
|
|
890
|
+
Logix4.Debug.record({
|
|
829
891
|
type: "trace:react.module-instance",
|
|
830
892
|
moduleId: ownerId,
|
|
831
893
|
instanceId: value.instanceId,
|
|
@@ -842,7 +904,7 @@ var ModuleCache = class {
|
|
|
842
904
|
}
|
|
843
905
|
return value;
|
|
844
906
|
} catch (error) {
|
|
845
|
-
void this.runtime.runPromise(
|
|
907
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
846
908
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
847
909
|
});
|
|
848
910
|
const entry = {
|
|
@@ -863,6 +925,49 @@ var ModuleCache = class {
|
|
|
863
925
|
throw error;
|
|
864
926
|
}
|
|
865
927
|
}
|
|
928
|
+
warmSync(key, factory, gcTime, ownerId, options) {
|
|
929
|
+
const existing = this.entries.get(key);
|
|
930
|
+
if (existing) {
|
|
931
|
+
if ((0, import_Env.isDevEnv)() && existing.ownerId !== void 0 && ownerId !== void 0 && existing.ownerId !== ownerId) {
|
|
932
|
+
throw new Error(
|
|
933
|
+
`[ModuleCache.warmSync] resource key "${key}" has already been claimed by module "${existing.ownerId}", but is now requested by module "${ownerId}".`
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
if (existing.status === "success") {
|
|
937
|
+
return existing.value;
|
|
938
|
+
}
|
|
939
|
+
return void 0;
|
|
940
|
+
}
|
|
941
|
+
const scope = this.runtime.runSync(import_effect5.Scope.make());
|
|
942
|
+
const startedAt = performance.now();
|
|
943
|
+
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
944
|
+
try {
|
|
945
|
+
const value = this.runtime.runSync(factory(scope));
|
|
946
|
+
const durationMs = performance.now() - startedAt;
|
|
947
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
948
|
+
const entry = {
|
|
949
|
+
scope,
|
|
950
|
+
status: "success",
|
|
951
|
+
promise: Promise.resolve(value),
|
|
952
|
+
value,
|
|
953
|
+
refCount: 0,
|
|
954
|
+
preloadRefCount: 0,
|
|
955
|
+
gcTime: gcTime ?? this.gcDelayMs,
|
|
956
|
+
ownerId,
|
|
957
|
+
createdBy: "preload",
|
|
958
|
+
workloadKey,
|
|
959
|
+
yieldStrategy: "none"
|
|
960
|
+
};
|
|
961
|
+
this.scheduleGC(key, entry);
|
|
962
|
+
this.entries.set(key, entry);
|
|
963
|
+
return value;
|
|
964
|
+
} catch (error) {
|
|
965
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
966
|
+
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
967
|
+
});
|
|
968
|
+
return void 0;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
866
971
|
preload(key, factory, options) {
|
|
867
972
|
const existing = this.entries.get(key);
|
|
868
973
|
if (existing) {
|
|
@@ -887,11 +992,43 @@ var ModuleCache = class {
|
|
|
887
992
|
}
|
|
888
993
|
};
|
|
889
994
|
}
|
|
890
|
-
const scope =
|
|
995
|
+
const scope = import_effect5.Effect.runSync(import_effect5.Scope.make());
|
|
891
996
|
const ownerId = options?.ownerId;
|
|
892
997
|
const gcTime = options?.gcTime ?? this.gcDelayMs;
|
|
893
998
|
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
894
999
|
const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
|
|
1000
|
+
const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
|
|
1001
|
+
const shouldTryOptimisticSync = options?.policyMode === "defer" && optimisticSyncBudgetMs > 0;
|
|
1002
|
+
if (shouldTryOptimisticSync) {
|
|
1003
|
+
const startedAt2 = performance.now();
|
|
1004
|
+
try {
|
|
1005
|
+
const value = this.runtime.runSync(factory(scope));
|
|
1006
|
+
const durationMs = performance.now() - startedAt2;
|
|
1007
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
1008
|
+
const entry2 = {
|
|
1009
|
+
scope,
|
|
1010
|
+
status: "success",
|
|
1011
|
+
promise: Promise.resolve(value),
|
|
1012
|
+
value,
|
|
1013
|
+
refCount: 0,
|
|
1014
|
+
preloadRefCount: 1,
|
|
1015
|
+
gcTime,
|
|
1016
|
+
ownerId,
|
|
1017
|
+
createdBy: "preload",
|
|
1018
|
+
workloadKey,
|
|
1019
|
+
yieldStrategy: "none"
|
|
1020
|
+
};
|
|
1021
|
+
this.scheduleGC(key, entry2);
|
|
1022
|
+
this.entries.set(key, entry2);
|
|
1023
|
+
return {
|
|
1024
|
+
promise: Promise.resolve(value),
|
|
1025
|
+
cancel: () => {
|
|
1026
|
+
this.cancelPreload(key, entry2);
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
} catch {
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
895
1032
|
const entry = {
|
|
896
1033
|
scope,
|
|
897
1034
|
status: "pending",
|
|
@@ -907,11 +1044,11 @@ var ModuleCache = class {
|
|
|
907
1044
|
this.scheduleGC(key, entry);
|
|
908
1045
|
this.entries.set(key, entry);
|
|
909
1046
|
const startedAt = performance.now();
|
|
910
|
-
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(
|
|
1047
|
+
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect5.Effect.flatMap(() => factory(scope)));
|
|
911
1048
|
const fiber = this.runtime.runFork(buildEffect);
|
|
912
1049
|
entry.fiber = fiber;
|
|
913
|
-
const promise = this.runtime.runPromise(
|
|
914
|
-
if (
|
|
1050
|
+
const promise = this.runtime.runPromise(import_effect5.Fiber.await(fiber)).then((exit) => {
|
|
1051
|
+
if (import_effect5.Exit.isSuccess(exit)) return exit.value;
|
|
915
1052
|
throw causeToUnknown(exit.cause);
|
|
916
1053
|
});
|
|
917
1054
|
entry.promise = promise;
|
|
@@ -937,7 +1074,7 @@ var ModuleCache = class {
|
|
|
937
1074
|
workloadKey,
|
|
938
1075
|
durationMs: performance.now() - startedAt
|
|
939
1076
|
});
|
|
940
|
-
void this.runtime.runPromise(
|
|
1077
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
941
1078
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
942
1079
|
});
|
|
943
1080
|
});
|
|
@@ -969,9 +1106,9 @@ var ModuleCache = class {
|
|
|
969
1106
|
entry.fiber = void 0;
|
|
970
1107
|
this.entries.delete(key);
|
|
971
1108
|
if (running) {
|
|
972
|
-
this.runtime.runFork(
|
|
1109
|
+
this.runtime.runFork(import_effect5.Fiber.interrupt(running));
|
|
973
1110
|
}
|
|
974
|
-
void this.runtime.runPromise(
|
|
1111
|
+
void this.runtime.runPromise(import_effect5.Scope.close(entry.scope, import_effect5.Exit.void)).catch((closeError) => {
|
|
975
1112
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
976
1113
|
});
|
|
977
1114
|
return;
|
|
@@ -1017,7 +1154,7 @@ var ModuleCache = class {
|
|
|
1017
1154
|
if (entry.gcTimeout) {
|
|
1018
1155
|
clearTimeout(entry.gcTimeout);
|
|
1019
1156
|
}
|
|
1020
|
-
void this.runtime.runPromise(
|
|
1157
|
+
void this.runtime.runPromise(import_effect5.Scope.close(entry.scope, import_effect5.Exit.void)).catch((error) => {
|
|
1021
1158
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", error);
|
|
1022
1159
|
});
|
|
1023
1160
|
this.entries.delete(key);
|
|
@@ -1073,6 +1210,7 @@ var isModuleRuntime = (value) => typeof value === "object" && value !== null &&
|
|
|
1073
1210
|
function useModuleRuntime(handle) {
|
|
1074
1211
|
const runtime = useRuntime();
|
|
1075
1212
|
const runtimeContext = (0, import_react4.useContext)(RuntimeContext);
|
|
1213
|
+
const moduleTagResolveTraceRef = (0, import_react4.useRef)(void 0);
|
|
1076
1214
|
if (!runtimeContext) {
|
|
1077
1215
|
throw new RuntimeProviderNotFoundError("useModuleRuntime");
|
|
1078
1216
|
}
|
|
@@ -1093,36 +1231,48 @@ function useModuleRuntime(handle) {
|
|
|
1093
1231
|
const preloadKey = runtimeContext.policy.preload?.keysByTagId.get(tokenId);
|
|
1094
1232
|
const key = preloadKey ?? `tag:${tokenId}`;
|
|
1095
1233
|
const mode = runtimeContext.policy.moduleTagMode;
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1234
|
+
const startedAtMs = performance.now();
|
|
1235
|
+
const factory = (scope) => import_effect6.Scope.provide(scope)(import_effect6.Effect.service(tag).pipe(import_effect6.Effect.orDie));
|
|
1236
|
+
const resolvedRuntime = mode === "suspend" ? cache.read(key, factory, void 0, tokenId, {
|
|
1098
1237
|
entrypoint: "react.useModuleRuntime",
|
|
1099
1238
|
policyMode: runtimeContext.policy.mode,
|
|
1100
|
-
yield: runtimeContext.policy.yield
|
|
1239
|
+
yield: runtimeContext.policy.yield,
|
|
1240
|
+
optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
|
|
1101
1241
|
}) : cache.readSync(key, factory, void 0, tokenId, {
|
|
1102
1242
|
entrypoint: "react.useModuleRuntime",
|
|
1103
1243
|
policyMode: runtimeContext.policy.mode,
|
|
1104
1244
|
warnSyncBlockingThresholdMs: 5
|
|
1105
1245
|
});
|
|
1246
|
+
moduleTagResolveTraceRef.current = {
|
|
1247
|
+
tokenId,
|
|
1248
|
+
durationMs: Math.round((performance.now() - startedAtMs) * 100) / 100,
|
|
1249
|
+
cacheMode: mode
|
|
1250
|
+
};
|
|
1251
|
+
return resolvedRuntime;
|
|
1106
1252
|
}, [cache, runtimeContext.policy, handle]);
|
|
1107
1253
|
(0, import_react4.useEffect)(() => {
|
|
1108
1254
|
if (!isTagHandle) {
|
|
1109
1255
|
return;
|
|
1110
1256
|
}
|
|
1111
|
-
|
|
1257
|
+
const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtime);
|
|
1258
|
+
if (diagnosticsLevel === "off") {
|
|
1112
1259
|
return;
|
|
1113
1260
|
}
|
|
1114
1261
|
const tokenId = handle?.id ?? "ModuleTag";
|
|
1115
|
-
const
|
|
1262
|
+
const trace = moduleTagResolveTraceRef.current;
|
|
1263
|
+
const effect = Logix5.Debug.record({
|
|
1116
1264
|
type: "trace:react.moduleTag.resolve",
|
|
1117
1265
|
moduleId: resolved.moduleId,
|
|
1118
1266
|
instanceId: resolved.instanceId,
|
|
1119
1267
|
data: {
|
|
1120
1268
|
mode: runtimeContext.policy.moduleTagMode,
|
|
1121
1269
|
tokenId,
|
|
1122
|
-
yieldStrategy: runtimeContext.policy.yield.strategy
|
|
1270
|
+
yieldStrategy: runtimeContext.policy.yield.strategy,
|
|
1271
|
+
durationMs: trace?.durationMs,
|
|
1272
|
+
cacheMode: trace?.cacheMode ?? runtimeContext.policy.moduleTagMode
|
|
1123
1273
|
}
|
|
1124
1274
|
});
|
|
1125
|
-
runtime
|
|
1275
|
+
emitRuntimeDebugEventBestEffort(runtime, effect);
|
|
1126
1276
|
}, [runtime, runtimeContext.policy, resolved, handle, isTagHandle]);
|
|
1127
1277
|
return resolved;
|
|
1128
1278
|
}
|
|
@@ -1130,11 +1280,11 @@ function useModuleRuntime(handle) {
|
|
|
1130
1280
|
// src/internal/hooks/useSelector.ts
|
|
1131
1281
|
var import_react5 = require("react");
|
|
1132
1282
|
var import_with_selector = require("use-sync-external-store/shim/with-selector");
|
|
1133
|
-
var
|
|
1283
|
+
var Logix7 = __toESM(require("@logixjs/core"), 1);
|
|
1134
1284
|
|
|
1135
1285
|
// src/internal/store/RuntimeExternalStore.ts
|
|
1136
|
-
var
|
|
1137
|
-
var
|
|
1286
|
+
var Logix6 = __toESM(require("@logixjs/core"), 1);
|
|
1287
|
+
var import_effect7 = require("effect");
|
|
1138
1288
|
var storesByRuntime = /* @__PURE__ */ new WeakMap();
|
|
1139
1289
|
var getStoreMapForRuntime = (runtime) => {
|
|
1140
1290
|
const cached = storesByRuntime.get(runtime);
|
|
@@ -1145,8 +1295,8 @@ var getStoreMapForRuntime = (runtime) => {
|
|
|
1145
1295
|
};
|
|
1146
1296
|
var makeModuleInstanceKey = (moduleId, instanceId) => `${moduleId}::${instanceId}`;
|
|
1147
1297
|
var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
|
|
1148
|
-
var getRuntimeStore = (runtime) =>
|
|
1149
|
-
var getHostScheduler = (runtime) =>
|
|
1298
|
+
var getRuntimeStore = (runtime) => Logix6.InternalContracts.getRuntimeStore(runtime);
|
|
1299
|
+
var getHostScheduler = (runtime) => Logix6.InternalContracts.getHostScheduler(runtime);
|
|
1150
1300
|
var getOrCreateStore = (runtime, topicKey, make) => {
|
|
1151
1301
|
const map = getStoreMapForRuntime(runtime);
|
|
1152
1302
|
const cached = map.get(topicKey);
|
|
@@ -1170,6 +1320,8 @@ var makeTopicExternalStore = (args) => {
|
|
|
1170
1320
|
let currentSnapshot;
|
|
1171
1321
|
const listeners = /* @__PURE__ */ new Set();
|
|
1172
1322
|
let unsubscribeFromRuntimeStore;
|
|
1323
|
+
let teardownScheduled = false;
|
|
1324
|
+
let teardownToken = 0;
|
|
1173
1325
|
const lowPriorityDelayMs = args.options?.lowPriorityDelayMs ?? 16;
|
|
1174
1326
|
const lowPriorityMaxDelayMs = args.options?.lowPriorityMaxDelayMs ?? 50;
|
|
1175
1327
|
let notifyScheduled = false;
|
|
@@ -1254,7 +1406,38 @@ var makeTopicExternalStore = (args) => {
|
|
|
1254
1406
|
currentSnapshot = next;
|
|
1255
1407
|
return next;
|
|
1256
1408
|
};
|
|
1409
|
+
const cancelScheduledTeardown = () => {
|
|
1410
|
+
if (!teardownScheduled) return;
|
|
1411
|
+
teardownScheduled = false;
|
|
1412
|
+
teardownToken += 1;
|
|
1413
|
+
};
|
|
1414
|
+
const finalizeTeardown = () => {
|
|
1415
|
+
if (listeners.size > 0) return;
|
|
1416
|
+
try {
|
|
1417
|
+
args.onLastListener?.();
|
|
1418
|
+
} catch {
|
|
1419
|
+
}
|
|
1420
|
+
const unsub = unsubscribeFromRuntimeStore;
|
|
1421
|
+
unsubscribeFromRuntimeStore = void 0;
|
|
1422
|
+
cancelLow();
|
|
1423
|
+
try {
|
|
1424
|
+
unsub?.();
|
|
1425
|
+
} catch {
|
|
1426
|
+
}
|
|
1427
|
+
removeStore(runtime, topicKey);
|
|
1428
|
+
};
|
|
1429
|
+
const scheduleTeardown = () => {
|
|
1430
|
+
if (teardownScheduled) return;
|
|
1431
|
+
teardownScheduled = true;
|
|
1432
|
+
const token = ++teardownToken;
|
|
1433
|
+
hostScheduler.scheduleMicrotask(() => {
|
|
1434
|
+
if (!teardownScheduled || token !== teardownToken) return;
|
|
1435
|
+
teardownScheduled = false;
|
|
1436
|
+
finalizeTeardown();
|
|
1437
|
+
});
|
|
1438
|
+
};
|
|
1257
1439
|
const subscribe = (listener) => {
|
|
1440
|
+
cancelScheduledTeardown();
|
|
1258
1441
|
const isFirst = listeners.size === 0;
|
|
1259
1442
|
listeners.add(listener);
|
|
1260
1443
|
ensureSubscription();
|
|
@@ -1268,18 +1451,7 @@ var makeTopicExternalStore = (args) => {
|
|
|
1268
1451
|
return () => {
|
|
1269
1452
|
listeners.delete(listener);
|
|
1270
1453
|
if (listeners.size > 0) return;
|
|
1271
|
-
|
|
1272
|
-
args.onLastListener?.();
|
|
1273
|
-
} catch {
|
|
1274
|
-
}
|
|
1275
|
-
const unsub = unsubscribeFromRuntimeStore;
|
|
1276
|
-
unsubscribeFromRuntimeStore = void 0;
|
|
1277
|
-
cancelLow();
|
|
1278
|
-
try {
|
|
1279
|
-
unsub?.();
|
|
1280
|
-
} catch {
|
|
1281
|
-
}
|
|
1282
|
-
removeStore(runtime, topicKey);
|
|
1454
|
+
scheduleTeardown();
|
|
1283
1455
|
};
|
|
1284
1456
|
};
|
|
1285
1457
|
return { getSnapshot, getServerSnapshot: getSnapshot, subscribe };
|
|
@@ -1323,14 +1495,14 @@ var getRuntimeReadQueryExternalStore = (runtime, moduleRuntime, selectorReadQuer
|
|
|
1323
1495
|
options,
|
|
1324
1496
|
onFirstListener: () => {
|
|
1325
1497
|
if (readQueryDrainFiber) return;
|
|
1326
|
-
const effect =
|
|
1498
|
+
const effect = import_effect7.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
|
|
1327
1499
|
readQueryDrainFiber = runtime.runFork(effect);
|
|
1328
1500
|
},
|
|
1329
1501
|
onLastListener: () => {
|
|
1330
1502
|
const fiber = readQueryDrainFiber;
|
|
1331
1503
|
if (!fiber) return;
|
|
1332
1504
|
readQueryDrainFiber = void 0;
|
|
1333
|
-
runtime.runFork(
|
|
1505
|
+
runtime.runFork(import_effect7.Fiber.interrupt(fiber));
|
|
1334
1506
|
}
|
|
1335
1507
|
})
|
|
1336
1508
|
);
|
|
@@ -1396,7 +1568,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1396
1568
|
const moduleRuntime = useModuleRuntime(handle);
|
|
1397
1569
|
const actualSelector = selector ?? ((state) => state);
|
|
1398
1570
|
const selectorReadQuery = (0, import_react5.useMemo)(
|
|
1399
|
-
() => typeof selector === "function" ?
|
|
1571
|
+
() => typeof selector === "function" ? Logix7.ReadQuery.compile(selector) : void 0,
|
|
1400
1572
|
[selector]
|
|
1401
1573
|
);
|
|
1402
1574
|
const actualEqualityFn = (0, import_react5.useMemo)(() => {
|
|
@@ -1434,7 +1606,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1434
1606
|
actualEqualityFn
|
|
1435
1607
|
);
|
|
1436
1608
|
(0, import_react5.useEffect)(() => {
|
|
1437
|
-
if (!(0, import_Env.isDevEnv)() && !
|
|
1609
|
+
if (!(0, import_Env.isDevEnv)() && !Logix7.Debug.isDevtoolsEnabled()) {
|
|
1438
1610
|
return;
|
|
1439
1611
|
}
|
|
1440
1612
|
const instanceId = moduleRuntime.instanceId;
|
|
@@ -1450,7 +1622,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1450
1622
|
const rawDebugKey = meta.debugKey;
|
|
1451
1623
|
selectorKey = typeof rawDebugKey === "string" && rawDebugKey.length > 0 ? rawDebugKey : typeof selector.name === "string" && selector.name.length > 0 ? selector.name : void 0;
|
|
1452
1624
|
}
|
|
1453
|
-
const effect =
|
|
1625
|
+
const effect = Logix7.Debug.record({
|
|
1454
1626
|
type: "trace:react-selector",
|
|
1455
1627
|
moduleId: moduleRuntime.moduleId,
|
|
1456
1628
|
instanceId,
|
|
@@ -1473,7 +1645,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1473
1645
|
}
|
|
1474
1646
|
|
|
1475
1647
|
// src/internal/store/resolveImportedModuleRef.ts
|
|
1476
|
-
var
|
|
1648
|
+
var Logix8 = __toESM(require("@logixjs/core"), 1);
|
|
1477
1649
|
var getOrCreateWeakMap = (map, key, make) => {
|
|
1478
1650
|
const cached = map.get(key);
|
|
1479
1651
|
if (cached) return cached;
|
|
@@ -1497,7 +1669,7 @@ var resolveImportedModuleRef = (runtime, parentRuntime, module2) => {
|
|
|
1497
1669
|
if (cached) {
|
|
1498
1670
|
return cached;
|
|
1499
1671
|
}
|
|
1500
|
-
const importsScope =
|
|
1672
|
+
const importsScope = Logix8.InternalContracts.getImportsScope(parentRuntime);
|
|
1501
1673
|
const childRuntime = importsScope.get(module2);
|
|
1502
1674
|
if (childRuntime) {
|
|
1503
1675
|
const dispatch = Object.assign(
|
|
@@ -1583,8 +1755,8 @@ var useStableId = () => {
|
|
|
1583
1755
|
|
|
1584
1756
|
// src/internal/hooks/useModule.ts
|
|
1585
1757
|
var isModuleImpl = (handle) => Boolean(handle) && typeof handle === "object" && handle._tag === "ModuleImpl";
|
|
1586
|
-
var isModule = (handle) =>
|
|
1587
|
-
var isModuleDef = (handle) =>
|
|
1758
|
+
var isModule = (handle) => Logix9.Module.hasImpl(handle);
|
|
1759
|
+
var isModuleDef = (handle) => Logix9.Module.is(handle) && handle._kind === "ModuleDef";
|
|
1588
1760
|
function useModule(handle, selectorOrOptions, equalityFn) {
|
|
1589
1761
|
const runtimeBase = useRuntime();
|
|
1590
1762
|
const runtimeContext = import_react7.default.useContext(RuntimeContext);
|
|
@@ -1608,6 +1780,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1608
1780
|
}
|
|
1609
1781
|
}
|
|
1610
1782
|
let runtime;
|
|
1783
|
+
const moduleImplResolveTraceRef = import_react7.default.useRef(void 0);
|
|
1611
1784
|
if (isModuleImpl(normalizedHandle)) {
|
|
1612
1785
|
const cache = import_react7.default.useMemo(
|
|
1613
1786
|
() => getModuleCache(runtimeBase, runtimeContext.reactConfigSnapshot, runtimeContext.configVersion),
|
|
@@ -1636,9 +1809,9 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1636
1809
|
const key = depsHash ? `${baseKey}:${depsHash}` : baseKey;
|
|
1637
1810
|
const ownerId = moduleId;
|
|
1638
1811
|
const baseFactory = import_react7.default.useMemo(
|
|
1639
|
-
() => (scope) =>
|
|
1640
|
-
|
|
1641
|
-
(context) =>
|
|
1812
|
+
() => (scope) => import_effect8.Layer.buildWithScope(import_effect8.Layer.fresh(normalizedHandle.layer), scope).pipe(
|
|
1813
|
+
import_effect8.Effect.map(
|
|
1814
|
+
(context) => import_effect8.ServiceMap.get(context, normalizedHandle.module)
|
|
1642
1815
|
)
|
|
1643
1816
|
),
|
|
1644
1817
|
[normalizedHandle]
|
|
@@ -1648,26 +1821,56 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1648
1821
|
return baseFactory;
|
|
1649
1822
|
}
|
|
1650
1823
|
return (scope) => baseFactory(scope).pipe(
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1824
|
+
import_effect8.Effect.timeoutOption(initTimeoutMs),
|
|
1825
|
+
import_effect8.Effect.flatMap(
|
|
1826
|
+
(maybe) => maybe._tag === "Some" ? import_effect8.Effect.succeed(maybe.value) : import_effect8.Effect.die(new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`))
|
|
1827
|
+
)
|
|
1655
1828
|
);
|
|
1656
1829
|
}, [baseFactory, suspend, initTimeoutMs, ownerId]);
|
|
1830
|
+
const moduleResolveStartedAt = performance.now();
|
|
1657
1831
|
const moduleRuntime = suspend ? cache.read(key, factory, gcTime, ownerId, {
|
|
1658
1832
|
entrypoint: "react.useModule",
|
|
1659
1833
|
policyMode: runtimeContext.policy.mode,
|
|
1660
|
-
yield: runtimeContext.policy.yield
|
|
1834
|
+
yield: runtimeContext.policy.yield,
|
|
1835
|
+
optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
|
|
1661
1836
|
}) : cache.readSync(key, factory, gcTime, ownerId, {
|
|
1662
1837
|
entrypoint: "react.useModule",
|
|
1663
1838
|
policyMode: runtimeContext.policy.mode,
|
|
1664
1839
|
warnSyncBlockingThresholdMs: 5
|
|
1665
1840
|
});
|
|
1841
|
+
moduleImplResolveTraceRef.current = {
|
|
1842
|
+
moduleId,
|
|
1843
|
+
cacheMode: suspend ? "suspend" : "sync",
|
|
1844
|
+
durationMs: Math.round((performance.now() - moduleResolveStartedAt) * 100) / 100
|
|
1845
|
+
};
|
|
1666
1846
|
import_react7.default.useEffect(() => cache.retain(key), [cache, key]);
|
|
1667
1847
|
runtime = moduleRuntime;
|
|
1668
1848
|
} else {
|
|
1669
1849
|
runtime = useModuleRuntime(normalizedHandle);
|
|
1670
1850
|
}
|
|
1851
|
+
import_react7.default.useEffect(() => {
|
|
1852
|
+
if (!isModuleImpl(normalizedHandle)) {
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtimeBase);
|
|
1856
|
+
if (diagnosticsLevel === "off") {
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
const trace = moduleImplResolveTraceRef.current;
|
|
1860
|
+
if (!trace) {
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
const effect = Logix9.Debug.record({
|
|
1864
|
+
type: "trace:react.moduleImpl.resolve",
|
|
1865
|
+
moduleId: trace.moduleId,
|
|
1866
|
+
instanceId: runtime.instanceId,
|
|
1867
|
+
data: {
|
|
1868
|
+
cacheMode: trace.cacheMode,
|
|
1869
|
+
durationMs: trace.durationMs
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
emitRuntimeDebugEventBestEffort(runtimeBase, effect);
|
|
1873
|
+
}, [runtimeBase, runtime, normalizedHandle]);
|
|
1671
1874
|
import_react7.default.useEffect(() => {
|
|
1672
1875
|
if (!isModuleImpl(normalizedHandle)) {
|
|
1673
1876
|
return;
|
|
@@ -1677,22 +1880,22 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1677
1880
|
if (!label) {
|
|
1678
1881
|
return;
|
|
1679
1882
|
}
|
|
1680
|
-
const effect =
|
|
1883
|
+
const effect = Logix9.Debug.record({
|
|
1681
1884
|
type: "trace:instanceLabel",
|
|
1682
1885
|
moduleId: normalizedHandle.module.id,
|
|
1683
1886
|
instanceId: runtime.instanceId,
|
|
1684
1887
|
data: { label }
|
|
1685
1888
|
});
|
|
1686
|
-
runtimeBase
|
|
1889
|
+
emitRuntimeDebugEventBestEffort(runtimeBase, effect);
|
|
1687
1890
|
}, [runtimeBase, runtime, normalizedHandle, options]);
|
|
1688
1891
|
import_react7.default.useEffect(() => {
|
|
1689
|
-
if (!(0, import_Env.isDevEnv)() && !
|
|
1892
|
+
if (!(0, import_Env.isDevEnv)() && !Logix9.Debug.isDevtoolsEnabled()) {
|
|
1690
1893
|
return;
|
|
1691
1894
|
}
|
|
1692
1895
|
if (!runtime.instanceId) {
|
|
1693
1896
|
return;
|
|
1694
1897
|
}
|
|
1695
|
-
const effect =
|
|
1898
|
+
const effect = Logix9.Debug.record({
|
|
1696
1899
|
type: "trace:react-render",
|
|
1697
1900
|
moduleId: runtime.moduleId,
|
|
1698
1901
|
instanceId: runtime.instanceId,
|
|
@@ -1702,7 +1905,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1702
1905
|
}
|
|
1703
1906
|
});
|
|
1704
1907
|
runtimeBase.runFork(effect);
|
|
1705
|
-
}
|
|
1908
|
+
});
|
|
1706
1909
|
if (selector) {
|
|
1707
1910
|
if (isModuleImpl(normalizedHandle)) {
|
|
1708
1911
|
return useSelector(runtime, selector, equalityFn);
|
|
@@ -1789,8 +1992,8 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1789
1992
|
|
|
1790
1993
|
// src/internal/hooks/useLocalModule.ts
|
|
1791
1994
|
var import_react8 = __toESM(require("react"), 1);
|
|
1792
|
-
var
|
|
1793
|
-
var
|
|
1995
|
+
var Logix10 = __toESM(require("@logixjs/core"), 1);
|
|
1996
|
+
var import_effect9 = require("effect");
|
|
1794
1997
|
function isModuleTag(source) {
|
|
1795
1998
|
if (!source || typeof source !== "object" && typeof source !== "function") {
|
|
1796
1999
|
return false;
|
|
@@ -1810,7 +2013,7 @@ function useLocalModule(source, second) {
|
|
|
1810
2013
|
);
|
|
1811
2014
|
const componentId = useStableId();
|
|
1812
2015
|
const moduleTag = import_react8.default.useMemo(() => {
|
|
1813
|
-
if (
|
|
2016
|
+
if (Logix10.Module.is(source)) {
|
|
1814
2017
|
return source.tag;
|
|
1815
2018
|
}
|
|
1816
2019
|
if (isModuleTag(source)) {
|
|
@@ -1819,7 +2022,7 @@ function useLocalModule(source, second) {
|
|
|
1819
2022
|
return null;
|
|
1820
2023
|
}, [source]);
|
|
1821
2024
|
const def = import_react8.default.useMemo(() => {
|
|
1822
|
-
if (
|
|
2025
|
+
if (Logix10.Module.is(source) || isModuleTag(source)) {
|
|
1823
2026
|
return source;
|
|
1824
2027
|
}
|
|
1825
2028
|
return void 0;
|
|
@@ -1847,7 +2050,7 @@ function useLocalModule(source, second) {
|
|
|
1847
2050
|
return createModuleTagFactory(moduleTag, moduleOptions);
|
|
1848
2051
|
}
|
|
1849
2052
|
const factoryFn = source;
|
|
1850
|
-
return (scope) =>
|
|
2053
|
+
return (scope) => import_effect9.Scope.provide(scope)(factoryFn());
|
|
1851
2054
|
}, [isModule2, moduleTag, source, moduleOptions]);
|
|
1852
2055
|
const moduleRuntime = cache.readSync(key, factory, void 0, ownerId, {
|
|
1853
2056
|
entrypoint: "react.useLocalModule",
|
|
@@ -1907,9 +2110,9 @@ function createModuleTagFactory(module2, options) {
|
|
|
1907
2110
|
throw new Error("useLocalModule(module, options) \u9700\u8981\u63D0\u4F9B initial \u72B6\u6001");
|
|
1908
2111
|
}
|
|
1909
2112
|
const logics = options.logics ?? [];
|
|
1910
|
-
return (scope) =>
|
|
1911
|
-
|
|
1912
|
-
const runtime =
|
|
2113
|
+
return (scope) => import_effect9.Layer.buildWithScope(module2.live(options.initial, ...logics), scope).pipe(
|
|
2114
|
+
import_effect9.Effect.map((context) => {
|
|
2115
|
+
const runtime = import_effect9.ServiceMap.get(context, module2);
|
|
1913
2116
|
return runtime;
|
|
1914
2117
|
})
|
|
1915
2118
|
);
|
|
@@ -1917,12 +2120,12 @@ function createModuleTagFactory(module2, options) {
|
|
|
1917
2120
|
|
|
1918
2121
|
// src/internal/hooks/useLayerModule.ts
|
|
1919
2122
|
var import_react9 = __toESM(require("react"), 1);
|
|
1920
|
-
var
|
|
2123
|
+
var import_effect10 = require("effect");
|
|
1921
2124
|
function useLayerModule(module2, layer, deps = []) {
|
|
1922
2125
|
const factory = import_react9.default.useCallback(
|
|
1923
|
-
() =>
|
|
1924
|
-
|
|
1925
|
-
|
|
2126
|
+
() => import_effect10.Layer.build(layer).pipe(
|
|
2127
|
+
import_effect10.Effect.scoped,
|
|
2128
|
+
import_effect10.Effect.map((context) => import_effect10.ServiceMap.get(context, module2))
|
|
1926
2129
|
),
|
|
1927
2130
|
// layer/module are typically constants; deps lets callers opt into rebuilding when needed.
|
|
1928
2131
|
[layer, module2]
|
|
@@ -1979,8 +2182,8 @@ function useImportedModule(parent, module2) {
|
|
|
1979
2182
|
|
|
1980
2183
|
// src/internal/hooks/useProcesses.ts
|
|
1981
2184
|
var import_react13 = __toESM(require("react"), 1);
|
|
1982
|
-
var
|
|
1983
|
-
var
|
|
2185
|
+
var import_effect11 = require("effect");
|
|
2186
|
+
var Logix11 = __toESM(require("@logixjs/core"), 1);
|
|
1984
2187
|
var ProcessSubtreeRegistry = class {
|
|
1985
2188
|
constructor(runtime) {
|
|
1986
2189
|
this.runtime = runtime;
|
|
@@ -2001,7 +2204,7 @@ var ProcessSubtreeRegistry = class {
|
|
|
2001
2204
|
}
|
|
2002
2205
|
return () => this.release({ key: args.key, gcTime: args.gcTime });
|
|
2003
2206
|
}
|
|
2004
|
-
const scope =
|
|
2207
|
+
const scope = import_effect11.Effect.runSync(import_effect11.Scope.make());
|
|
2005
2208
|
const entry = {
|
|
2006
2209
|
key: args.key,
|
|
2007
2210
|
signature: args.signature,
|
|
@@ -2029,7 +2232,7 @@ var ProcessSubtreeRegistry = class {
|
|
|
2029
2232
|
const current = this.entries.get(entry.key);
|
|
2030
2233
|
if (!current || current !== entry) return;
|
|
2031
2234
|
if (current.refCount > 0) return;
|
|
2032
|
-
void this.runtime.runPromise(
|
|
2235
|
+
void this.runtime.runPromise(import_effect11.Scope.close(entry.scope, import_effect11.Exit.void)).catch(() => {
|
|
2033
2236
|
});
|
|
2034
2237
|
this.entries.delete(entry.key);
|
|
2035
2238
|
}, timeoutMs);
|
|
@@ -2046,7 +2249,7 @@ var getRegistry = (runtime) => {
|
|
|
2046
2249
|
var stableProcessSignature = (processes) => {
|
|
2047
2250
|
const ids = [];
|
|
2048
2251
|
for (let i = 0; i < processes.length; i++) {
|
|
2049
|
-
const def =
|
|
2252
|
+
const def = Logix11.Process.getDefinition(processes[i]);
|
|
2050
2253
|
ids.push(def?.processId ?? `legacy#${i}`);
|
|
2051
2254
|
}
|
|
2052
2255
|
return ids.join("|");
|
|
@@ -2089,24 +2292,24 @@ function useProcesses(processes, options) {
|
|
|
2089
2292
|
signature,
|
|
2090
2293
|
gcTime,
|
|
2091
2294
|
install: (scope) => {
|
|
2092
|
-
const program =
|
|
2295
|
+
const program = import_effect11.Effect.forEach(
|
|
2093
2296
|
processes,
|
|
2094
|
-
(process) =>
|
|
2297
|
+
(process) => Logix11.InternalContracts.installProcess(process, {
|
|
2095
2298
|
scope: { type: "uiSubtree", subtreeId },
|
|
2096
2299
|
enabled: true,
|
|
2097
2300
|
installedAt: "uiSubtree",
|
|
2098
2301
|
mode
|
|
2099
2302
|
}).pipe(
|
|
2100
|
-
|
|
2303
|
+
import_effect11.Effect.flatMap((installation) => {
|
|
2101
2304
|
if (installation !== void 0) {
|
|
2102
|
-
return
|
|
2305
|
+
return import_effect11.Effect.void;
|
|
2103
2306
|
}
|
|
2104
|
-
return
|
|
2307
|
+
return import_effect11.Effect.forkScoped(process).pipe(import_effect11.Effect.asVoid);
|
|
2105
2308
|
}),
|
|
2106
|
-
|
|
2309
|
+
import_effect11.Effect.catch(() => import_effect11.Effect.forkScoped(process).pipe(import_effect11.Effect.asVoid))
|
|
2107
2310
|
),
|
|
2108
2311
|
{ discard: true }
|
|
2109
|
-
).pipe(
|
|
2312
|
+
).pipe(import_effect11.Effect.provideService(import_effect11.Scope.Scope, scope));
|
|
2110
2313
|
void runtime.runPromise(program).catch(() => {
|
|
2111
2314
|
});
|
|
2112
2315
|
}
|