@logixjs/react 0.1.0 → 0.1.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 CHANGED
@@ -336,8 +336,8 @@ function useRuntime(options) {
336
336
 
337
337
  // src/internal/hooks/useModule.ts
338
338
  var import_react7 = __toESM(require("react"), 1);
339
- var Logix7 = __toESM(require("@logixjs/core"), 1);
340
- var import_effect8 = require("effect");
339
+ var Logix8 = __toESM(require("@logixjs/core"), 1);
340
+ var import_effect7 = require("effect");
341
341
 
342
342
  // src/internal/hooks/useModuleRuntime.ts
343
343
  var import_react4 = require("react");
@@ -1130,55 +1130,71 @@ function useModuleRuntime(handle) {
1130
1130
  // src/internal/hooks/useSelector.ts
1131
1131
  var import_react5 = require("react");
1132
1132
  var import_with_selector = require("use-sync-external-store/shim/with-selector");
1133
- var Logix5 = __toESM(require("@logixjs/core"), 1);
1133
+ var Logix6 = __toESM(require("@logixjs/core"), 1);
1134
1134
 
1135
- // src/internal/store/ModuleRuntimeExternalStore.ts
1135
+ // src/internal/store/RuntimeExternalStore.ts
1136
+ var Logix5 = __toESM(require("@logixjs/core"), 1);
1136
1137
  var import_effect6 = require("effect");
1137
1138
  var storesByRuntime = /* @__PURE__ */ new WeakMap();
1138
1139
  var getStoreMapForRuntime = (runtime) => {
1139
1140
  const cached = storesByRuntime.get(runtime);
1140
1141
  if (cached) return cached;
1141
- const next = /* @__PURE__ */ new WeakMap();
1142
+ const next = /* @__PURE__ */ new Map();
1142
1143
  storesByRuntime.set(runtime, next);
1143
1144
  return next;
1144
1145
  };
1145
- var getModuleRuntimeExternalStore = (runtime, moduleRuntime, options) => {
1146
- const byModule = getStoreMapForRuntime(runtime);
1147
- const cached = byModule.get(moduleRuntime);
1146
+ var makeModuleInstanceKey = (moduleId, instanceId) => `${moduleId}::${instanceId}`;
1147
+ var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
1148
+ var getRuntimeStore = (runtime) => Logix5.InternalContracts.getRuntimeStore(runtime);
1149
+ var getHostScheduler = (runtime) => Logix5.InternalContracts.getHostScheduler(runtime);
1150
+ var getOrCreateStore = (runtime, topicKey, make) => {
1151
+ const map = getStoreMapForRuntime(runtime);
1152
+ const cached = map.get(topicKey);
1148
1153
  if (cached) {
1149
1154
  return cached;
1150
1155
  }
1151
- let currentState;
1156
+ const created = make();
1157
+ map.set(topicKey, created);
1158
+ return created;
1159
+ };
1160
+ var removeStore = (runtime, topicKey) => {
1161
+ const map = storesByRuntime.get(runtime);
1162
+ if (!map) return;
1163
+ map.delete(topicKey);
1164
+ };
1165
+ var makeTopicExternalStore = (args) => {
1166
+ const { runtime, runtimeStore, topicKey } = args;
1167
+ const hostScheduler = getHostScheduler(runtime);
1168
+ let currentVersion;
1169
+ let hasSnapshot = false;
1170
+ let currentSnapshot;
1152
1171
  const listeners = /* @__PURE__ */ new Set();
1153
- const lowPriorityDelayMs = options?.lowPriorityDelayMs ?? 16;
1154
- const lowPriorityMaxDelayMs = options?.lowPriorityMaxDelayMs ?? 50;
1172
+ let unsubscribeFromRuntimeStore;
1173
+ const lowPriorityDelayMs = args.options?.lowPriorityDelayMs ?? 16;
1174
+ const lowPriorityMaxDelayMs = args.options?.lowPriorityMaxDelayMs ?? 50;
1155
1175
  let notifyScheduled = false;
1156
1176
  let notifyScheduledLow = false;
1157
- let lowTimeoutId;
1158
- let lowMaxTimeoutId;
1159
- let lowRafId;
1177
+ let lowCancelDelay;
1178
+ let lowCancelMaxDelay;
1179
+ let lowCancelRaf;
1160
1180
  const cancelLow = () => {
1161
1181
  if (!notifyScheduledLow) return;
1162
1182
  notifyScheduledLow = false;
1163
- if (lowTimeoutId != null) {
1164
- clearTimeout(lowTimeoutId);
1165
- lowTimeoutId = void 0;
1166
- }
1167
- if (lowMaxTimeoutId != null) {
1168
- clearTimeout(lowMaxTimeoutId);
1169
- lowMaxTimeoutId = void 0;
1170
- }
1171
- const cancel = globalThis.cancelAnimationFrame;
1172
- if (cancel && typeof lowRafId === "number") {
1173
- cancel(lowRafId);
1174
- lowRafId = void 0;
1175
- }
1183
+ lowCancelDelay?.();
1184
+ lowCancelDelay = void 0;
1185
+ lowCancelMaxDelay?.();
1186
+ lowCancelMaxDelay = void 0;
1187
+ lowCancelRaf?.();
1188
+ lowCancelRaf = void 0;
1176
1189
  };
1177
1190
  const flushNotify = () => {
1178
1191
  notifyScheduled = false;
1179
1192
  cancelLow();
1180
1193
  for (const listener of listeners) {
1181
- listener();
1194
+ try {
1195
+ listener();
1196
+ } catch {
1197
+ }
1182
1198
  }
1183
1199
  };
1184
1200
  const scheduleNotify = (priority) => {
@@ -1190,72 +1206,135 @@ var getModuleRuntimeExternalStore = (runtime, moduleRuntime, options) => {
1190
1206
  if (!notifyScheduledLow) return;
1191
1207
  flushNotify();
1192
1208
  };
1193
- const raf = globalThis.requestAnimationFrame;
1194
- if (raf) {
1195
- lowRafId = raf(flush);
1209
+ const scheduleRaf = () => {
1210
+ if (!notifyScheduledLow) return;
1211
+ lowCancelRaf = hostScheduler.scheduleAnimationFrame(flush);
1212
+ };
1213
+ if (lowPriorityDelayMs <= 0) {
1214
+ scheduleRaf();
1196
1215
  } else {
1197
- lowTimeoutId = setTimeout(flush, lowPriorityDelayMs);
1216
+ lowCancelDelay = hostScheduler.scheduleTimeout(lowPriorityDelayMs, scheduleRaf);
1198
1217
  }
1199
- lowMaxTimeoutId = setTimeout(flush, lowPriorityMaxDelayMs);
1218
+ lowCancelMaxDelay = hostScheduler.scheduleTimeout(lowPriorityMaxDelayMs, flush);
1200
1219
  return;
1201
1220
  }
1202
1221
  cancelLow();
1203
1222
  if (notifyScheduled) return;
1204
1223
  notifyScheduled = true;
1205
- queueMicrotask(flushNotify);
1224
+ hostScheduler.scheduleMicrotask(flushNotify);
1225
+ };
1226
+ const onRuntimeStoreChange = () => {
1227
+ try {
1228
+ scheduleNotify(runtimeStore.getTopicPriority(topicKey));
1229
+ } catch {
1230
+ }
1206
1231
  };
1207
- let fiber;
1208
1232
  const ensureSubscription = () => {
1209
- if (fiber) return;
1210
- fiber = runtime.runFork(
1211
- import_effect6.Stream.runForEach(
1212
- moduleRuntime.changesWithMeta((state) => state),
1213
- ({ value: state, meta }) => import_effect6.Effect.sync(() => {
1214
- currentState = state;
1215
- scheduleNotify(meta.priority);
1216
- })
1217
- )
1218
- );
1233
+ if (unsubscribeFromRuntimeStore) return;
1234
+ unsubscribeFromRuntimeStore = runtimeStore.subscribeTopic(topicKey, onRuntimeStoreChange);
1219
1235
  };
1220
1236
  const refreshSnapshotIfStale = () => {
1221
- if (currentState === void 0) {
1222
- return;
1223
- }
1237
+ if (!hasSnapshot) return;
1224
1238
  try {
1225
- const latest = runtime.runSync(moduleRuntime.getState);
1226
- if (currentState === void 0 || !Object.is(currentState, latest)) {
1227
- currentState = latest;
1228
- scheduleNotify("normal");
1239
+ const version = runtimeStore.getTopicVersion(topicKey);
1240
+ if (currentVersion !== version) {
1241
+ scheduleNotify(runtimeStore.getTopicPriority(topicKey));
1229
1242
  }
1230
1243
  } catch {
1231
1244
  }
1232
1245
  };
1233
1246
  const getSnapshot = () => {
1234
- if (currentState !== void 0) return currentState;
1235
- currentState = runtime.runSync(moduleRuntime.getState);
1236
- return currentState;
1247
+ const version = runtimeStore.getTopicVersion(topicKey);
1248
+ if (hasSnapshot && currentVersion === version) {
1249
+ return currentSnapshot;
1250
+ }
1251
+ const next = args.readSnapshot();
1252
+ currentVersion = version;
1253
+ hasSnapshot = true;
1254
+ currentSnapshot = next;
1255
+ return next;
1237
1256
  };
1238
1257
  const subscribe = (listener) => {
1258
+ const isFirst = listeners.size === 0;
1239
1259
  listeners.add(listener);
1240
1260
  ensureSubscription();
1241
1261
  refreshSnapshotIfStale();
1262
+ if (isFirst) {
1263
+ try {
1264
+ args.onFirstListener?.();
1265
+ } catch {
1266
+ }
1267
+ }
1242
1268
  return () => {
1243
1269
  listeners.delete(listener);
1244
1270
  if (listeners.size > 0) return;
1245
- const running = fiber;
1246
- if (!running) return;
1247
- fiber = void 0;
1271
+ try {
1272
+ args.onLastListener?.();
1273
+ } catch {
1274
+ }
1275
+ const unsub = unsubscribeFromRuntimeStore;
1276
+ unsubscribeFromRuntimeStore = void 0;
1248
1277
  cancelLow();
1249
- runtime.runFork(import_effect6.Fiber.interrupt(running));
1278
+ try {
1279
+ unsub?.();
1280
+ } catch {
1281
+ }
1282
+ removeStore(runtime, topicKey);
1250
1283
  };
1251
1284
  };
1252
- const store = { getSnapshot, subscribe };
1253
- byModule.set(moduleRuntime, store);
1254
- return store;
1285
+ return { getSnapshot, getServerSnapshot: getSnapshot, subscribe };
1286
+ };
1287
+ var getRuntimeModuleExternalStore = (runtime, moduleRuntime, options) => {
1288
+ const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
1289
+ const runtimeStore = getRuntimeStore(runtime);
1290
+ return getOrCreateStore(
1291
+ runtime,
1292
+ moduleInstanceKey,
1293
+ () => makeTopicExternalStore({
1294
+ runtime,
1295
+ runtimeStore,
1296
+ topicKey: moduleInstanceKey,
1297
+ readSnapshot: () => {
1298
+ const state = runtimeStore.getModuleState(moduleInstanceKey);
1299
+ if (state !== void 0) return state;
1300
+ return runtime.runSync(moduleRuntime.getState);
1301
+ },
1302
+ options
1303
+ })
1304
+ );
1305
+ };
1306
+ var getRuntimeReadQueryExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
1307
+ const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
1308
+ const topicKey = makeReadQueryTopicKey(moduleInstanceKey, selectorReadQuery.selectorId);
1309
+ const runtimeStore = getRuntimeStore(runtime);
1310
+ let readQueryDrainFiber;
1311
+ return getOrCreateStore(
1312
+ runtime,
1313
+ topicKey,
1314
+ () => makeTopicExternalStore({
1315
+ runtime,
1316
+ runtimeStore,
1317
+ topicKey,
1318
+ readSnapshot: () => {
1319
+ const state = runtimeStore.getModuleState(moduleInstanceKey);
1320
+ const current = state ?? runtime.runSync(moduleRuntime.getState);
1321
+ return selectorReadQuery.select(current);
1322
+ },
1323
+ options,
1324
+ onFirstListener: () => {
1325
+ if (readQueryDrainFiber) return;
1326
+ const effect = import_effect6.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
1327
+ readQueryDrainFiber = runtime.runFork(effect);
1328
+ },
1329
+ onLastListener: () => {
1330
+ const fiber = readQueryDrainFiber;
1331
+ if (!fiber) return;
1332
+ readQueryDrainFiber = void 0;
1333
+ runtime.runFork(import_effect6.Fiber.interrupt(fiber));
1334
+ }
1335
+ })
1336
+ );
1255
1337
  };
1256
-
1257
- // src/internal/store/ModuleRuntimeSelectorExternalStore.ts
1258
- var import_effect7 = require("effect");
1259
1338
 
1260
1339
  // src/internal/hooks/shallow.ts
1261
1340
  var hasObjectShape = (value) => typeof value === "object" && value !== null;
@@ -1307,146 +1386,6 @@ var shallow = (previous, next) => {
1307
1386
  return true;
1308
1387
  };
1309
1388
 
1310
- // src/internal/store/ModuleRuntimeSelectorExternalStore.ts
1311
- var storesByRuntime2 = /* @__PURE__ */ new WeakMap();
1312
- var getStoreMapForRuntime2 = (runtime) => {
1313
- const cached = storesByRuntime2.get(runtime);
1314
- if (cached) return cached;
1315
- const next = /* @__PURE__ */ new WeakMap();
1316
- storesByRuntime2.set(runtime, next);
1317
- return next;
1318
- };
1319
- var getOrCreateSelectorMapForModule = (byModule, moduleRuntime) => {
1320
- const cached = byModule.get(moduleRuntime);
1321
- if (cached) return cached;
1322
- const next = /* @__PURE__ */ new Map();
1323
- byModule.set(moduleRuntime, next);
1324
- return next;
1325
- };
1326
- var equalsValue = (readQuery, a, b) => {
1327
- if (readQuery.equalsKind === "custom" && typeof readQuery.equals === "function") {
1328
- return readQuery.equals(a, b);
1329
- }
1330
- if (readQuery.equalsKind === "shallowStruct") {
1331
- return shallow(a, b);
1332
- }
1333
- return Object.is(a, b);
1334
- };
1335
- var getModuleRuntimeSelectorExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
1336
- const byModule = getStoreMapForRuntime2(runtime);
1337
- const bySelector = getOrCreateSelectorMapForModule(byModule, moduleRuntime);
1338
- const cached = bySelector.get(selectorReadQuery.selectorId);
1339
- if (cached) {
1340
- return cached;
1341
- }
1342
- let currentValue;
1343
- const listeners = /* @__PURE__ */ new Set();
1344
- const lowPriorityDelayMs = options?.lowPriorityDelayMs ?? 16;
1345
- const lowPriorityMaxDelayMs = options?.lowPriorityMaxDelayMs ?? 50;
1346
- let notifyScheduled = false;
1347
- let notifyScheduledLow = false;
1348
- let lowTimeoutId;
1349
- let lowMaxTimeoutId;
1350
- let lowRafId;
1351
- const cancelLow = () => {
1352
- if (!notifyScheduledLow) return;
1353
- notifyScheduledLow = false;
1354
- if (lowTimeoutId != null) {
1355
- clearTimeout(lowTimeoutId);
1356
- lowTimeoutId = void 0;
1357
- }
1358
- if (lowMaxTimeoutId != null) {
1359
- clearTimeout(lowMaxTimeoutId);
1360
- lowMaxTimeoutId = void 0;
1361
- }
1362
- const cancel = globalThis.cancelAnimationFrame;
1363
- if (cancel && typeof lowRafId === "number") {
1364
- cancel(lowRafId);
1365
- lowRafId = void 0;
1366
- }
1367
- };
1368
- const flushNotify = () => {
1369
- notifyScheduled = false;
1370
- cancelLow();
1371
- for (const listener of listeners) {
1372
- listener();
1373
- }
1374
- };
1375
- const scheduleNotify = (priority) => {
1376
- if (priority === "low") {
1377
- if (notifyScheduled) return;
1378
- if (notifyScheduledLow) return;
1379
- notifyScheduledLow = true;
1380
- const flush = () => {
1381
- if (!notifyScheduledLow) return;
1382
- flushNotify();
1383
- };
1384
- const raf = globalThis.requestAnimationFrame;
1385
- if (raf) {
1386
- lowRafId = raf(flush);
1387
- } else {
1388
- lowTimeoutId = setTimeout(flush, lowPriorityDelayMs);
1389
- }
1390
- lowMaxTimeoutId = setTimeout(flush, lowPriorityMaxDelayMs);
1391
- return;
1392
- }
1393
- cancelLow();
1394
- if (notifyScheduled) return;
1395
- notifyScheduled = true;
1396
- queueMicrotask(flushNotify);
1397
- };
1398
- let fiber;
1399
- const ensureSubscription = () => {
1400
- if (fiber) return;
1401
- fiber = runtime.runFork(
1402
- import_effect7.Stream.runForEach(
1403
- moduleRuntime.changesReadQueryWithMeta(selectorReadQuery),
1404
- ({ value, meta }) => import_effect7.Effect.sync(() => {
1405
- currentValue = value;
1406
- scheduleNotify(meta.priority);
1407
- })
1408
- )
1409
- );
1410
- };
1411
- const refreshSnapshotIfStale = () => {
1412
- if (currentValue === void 0) {
1413
- return;
1414
- }
1415
- try {
1416
- const state = runtime.runSync(moduleRuntime.getState);
1417
- const next = selectorReadQuery.select(state);
1418
- if (currentValue === void 0 || !equalsValue(selectorReadQuery, currentValue, next)) {
1419
- currentValue = next;
1420
- scheduleNotify("normal");
1421
- }
1422
- } catch {
1423
- }
1424
- };
1425
- const getSnapshot = () => {
1426
- if (currentValue !== void 0) return currentValue;
1427
- const state = runtime.runSync(moduleRuntime.getState);
1428
- currentValue = selectorReadQuery.select(state);
1429
- return currentValue;
1430
- };
1431
- const subscribe = (listener) => {
1432
- listeners.add(listener);
1433
- ensureSubscription();
1434
- refreshSnapshotIfStale();
1435
- return () => {
1436
- listeners.delete(listener);
1437
- if (listeners.size > 0) return;
1438
- const running = fiber;
1439
- if (!running) return;
1440
- fiber = void 0;
1441
- cancelLow();
1442
- runtime.runFork(import_effect7.Fiber.interrupt(running));
1443
- };
1444
- };
1445
- const store = { getSnapshot, subscribe };
1446
- bySelector.set(selectorReadQuery.selectorId, store);
1447
- return store;
1448
- };
1449
-
1450
1389
  // src/internal/hooks/useSelector.ts
1451
1390
  function useSelector(handle, selector, equalityFn) {
1452
1391
  const runtimeContext = (0, import_react5.useContext)(RuntimeContext);
@@ -1457,7 +1396,7 @@ function useSelector(handle, selector, equalityFn) {
1457
1396
  const moduleRuntime = useModuleRuntime(handle);
1458
1397
  const actualSelector = selector ?? ((state) => state);
1459
1398
  const selectorReadQuery = (0, import_react5.useMemo)(
1460
- () => typeof selector === "function" ? Logix5.ReadQuery.compile(selector) : void 0,
1399
+ () => typeof selector === "function" ? Logix6.ReadQuery.compile(selector) : void 0,
1461
1400
  [selector]
1462
1401
  );
1463
1402
  const actualEqualityFn = (0, import_react5.useMemo)(() => {
@@ -1465,17 +1404,12 @@ function useSelector(handle, selector, equalityFn) {
1465
1404
  if (typeof selector !== "function") return Object.is;
1466
1405
  return selectorReadQuery?.equalsKind === "shallowStruct" ? shallow : Object.is;
1467
1406
  }, [equalityFn, selector, selectorReadQuery?.equalsKind]);
1468
- const useStaticLane = typeof selector === "function" && selectorReadQuery?.lane === "static";
1407
+ const selectorTopicEligible = typeof selector === "function" && selectorReadQuery?.lane === "static" && selectorReadQuery.readsDigest != null && selectorReadQuery.fallbackReason == null;
1469
1408
  const store = (0, import_react5.useMemo)(
1470
- () => useStaticLane && selectorReadQuery ? getModuleRuntimeSelectorExternalStore(
1471
- runtime,
1472
- moduleRuntime,
1473
- selectorReadQuery,
1474
- {
1475
- lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
1476
- lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
1477
- }
1478
- ) : getModuleRuntimeExternalStore(
1409
+ () => selectorTopicEligible && selectorReadQuery ? getRuntimeReadQueryExternalStore(runtime, moduleRuntime, selectorReadQuery, {
1410
+ lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
1411
+ lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
1412
+ }) : getRuntimeModuleExternalStore(
1479
1413
  runtime,
1480
1414
  moduleRuntime,
1481
1415
  {
@@ -1489,18 +1423,18 @@ function useSelector(handle, selector, equalityFn) {
1489
1423
  runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
1490
1424
  runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs,
1491
1425
  selectorReadQuery,
1492
- useStaticLane
1426
+ selectorTopicEligible
1493
1427
  ]
1494
1428
  );
1495
1429
  const selected = (0, import_with_selector.useSyncExternalStoreWithSelector)(
1496
1430
  store.subscribe,
1497
1431
  store.getSnapshot,
1498
- store.getSnapshot,
1499
- useStaticLane ? (snapshot) => snapshot : (snapshot) => actualSelector(snapshot),
1432
+ store.getServerSnapshot ?? store.getSnapshot,
1433
+ selectorTopicEligible ? (snapshot) => snapshot : (snapshot) => actualSelector(snapshot),
1500
1434
  actualEqualityFn
1501
1435
  );
1502
1436
  (0, import_react5.useEffect)(() => {
1503
- if (!(0, import_Env.isDevEnv)() && !Logix5.Debug.isDevtoolsEnabled()) {
1437
+ if (!(0, import_Env.isDevEnv)() && !Logix6.Debug.isDevtoolsEnabled()) {
1504
1438
  return;
1505
1439
  }
1506
1440
  const instanceId = moduleRuntime.instanceId;
@@ -1516,7 +1450,7 @@ function useSelector(handle, selector, equalityFn) {
1516
1450
  const rawDebugKey = meta.debugKey;
1517
1451
  selectorKey = typeof rawDebugKey === "string" && rawDebugKey.length > 0 ? rawDebugKey : typeof selector.name === "string" && selector.name.length > 0 ? selector.name : void 0;
1518
1452
  }
1519
- const effect = Logix5.Debug.record({
1453
+ const effect = Logix6.Debug.record({
1520
1454
  type: "trace:react-selector",
1521
1455
  moduleId: moduleRuntime.moduleId,
1522
1456
  instanceId,
@@ -1539,7 +1473,7 @@ function useSelector(handle, selector, equalityFn) {
1539
1473
  }
1540
1474
 
1541
1475
  // src/internal/store/resolveImportedModuleRef.ts
1542
- var Logix6 = __toESM(require("@logixjs/core"), 1);
1476
+ var Logix7 = __toESM(require("@logixjs/core"), 1);
1543
1477
  var getOrCreateWeakMap = (map, key, make) => {
1544
1478
  const cached = map.get(key);
1545
1479
  if (cached) return cached;
@@ -1563,7 +1497,7 @@ var resolveImportedModuleRef = (runtime, parentRuntime, module2) => {
1563
1497
  if (cached) {
1564
1498
  return cached;
1565
1499
  }
1566
- const importsScope = Logix6.InternalContracts.getImportsScope(parentRuntime);
1500
+ const importsScope = Logix7.InternalContracts.getImportsScope(parentRuntime);
1567
1501
  const childRuntime = importsScope.get(module2);
1568
1502
  if (childRuntime) {
1569
1503
  const dispatch = Object.assign(
@@ -1649,8 +1583,8 @@ var useStableId = () => {
1649
1583
 
1650
1584
  // src/internal/hooks/useModule.ts
1651
1585
  var isModuleImpl = (handle) => Boolean(handle) && typeof handle === "object" && handle._tag === "ModuleImpl";
1652
- var isModule = (handle) => Logix7.Module.hasImpl(handle);
1653
- var isModuleDef = (handle) => Logix7.Module.is(handle) && handle._kind === "ModuleDef";
1586
+ var isModule = (handle) => Logix8.Module.hasImpl(handle);
1587
+ var isModuleDef = (handle) => Logix8.Module.is(handle) && handle._kind === "ModuleDef";
1654
1588
  function useModule(handle, selectorOrOptions, equalityFn) {
1655
1589
  const runtimeBase = useRuntime();
1656
1590
  const runtimeContext = import_react7.default.useContext(RuntimeContext);
@@ -1702,9 +1636,9 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1702
1636
  const key = depsHash ? `${baseKey}:${depsHash}` : baseKey;
1703
1637
  const ownerId = moduleId;
1704
1638
  const baseFactory = import_react7.default.useMemo(
1705
- () => (scope) => import_effect8.Layer.buildWithScope(normalizedHandle.layer, scope).pipe(
1706
- import_effect8.Effect.map(
1707
- (context) => import_effect8.Context.get(context, normalizedHandle.module)
1639
+ () => (scope) => import_effect7.Layer.buildWithScope(normalizedHandle.layer, scope).pipe(
1640
+ import_effect7.Effect.map(
1641
+ (context) => import_effect7.Context.get(context, normalizedHandle.module)
1708
1642
  )
1709
1643
  ),
1710
1644
  [normalizedHandle]
@@ -1714,7 +1648,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1714
1648
  return baseFactory;
1715
1649
  }
1716
1650
  return (scope) => baseFactory(scope).pipe(
1717
- import_effect8.Effect.timeoutFail({
1651
+ import_effect7.Effect.timeoutFail({
1718
1652
  duration: initTimeoutMs,
1719
1653
  onTimeout: () => new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`)
1720
1654
  })
@@ -1743,7 +1677,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1743
1677
  if (!label) {
1744
1678
  return;
1745
1679
  }
1746
- const effect = Logix7.Debug.record({
1680
+ const effect = Logix8.Debug.record({
1747
1681
  type: "trace:instanceLabel",
1748
1682
  moduleId: normalizedHandle.module.id,
1749
1683
  instanceId: runtime.instanceId,
@@ -1752,13 +1686,13 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1752
1686
  runtimeBase.runFork(effect);
1753
1687
  }, [runtimeBase, runtime, normalizedHandle, options]);
1754
1688
  import_react7.default.useEffect(() => {
1755
- if (!(0, import_Env.isDevEnv)() && !Logix7.Debug.isDevtoolsEnabled()) {
1689
+ if (!(0, import_Env.isDevEnv)() && !Logix8.Debug.isDevtoolsEnabled()) {
1756
1690
  return;
1757
1691
  }
1758
1692
  if (!runtime.instanceId) {
1759
1693
  return;
1760
1694
  }
1761
- const effect = Logix7.Debug.record({
1695
+ const effect = Logix8.Debug.record({
1762
1696
  type: "trace:react-render",
1763
1697
  moduleId: runtime.moduleId,
1764
1698
  instanceId: runtime.instanceId,
@@ -1855,8 +1789,8 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1855
1789
 
1856
1790
  // src/internal/hooks/useLocalModule.ts
1857
1791
  var import_react8 = __toESM(require("react"), 1);
1858
- var Logix8 = __toESM(require("@logixjs/core"), 1);
1859
- var import_effect9 = require("effect");
1792
+ var Logix9 = __toESM(require("@logixjs/core"), 1);
1793
+ var import_effect8 = require("effect");
1860
1794
  function isModuleTag(source) {
1861
1795
  if (!source || typeof source !== "object" && typeof source !== "function") {
1862
1796
  return false;
@@ -1876,7 +1810,7 @@ function useLocalModule(source, second) {
1876
1810
  );
1877
1811
  const componentId = useStableId();
1878
1812
  const moduleTag = import_react8.default.useMemo(() => {
1879
- if (Logix8.Module.is(source)) {
1813
+ if (Logix9.Module.is(source)) {
1880
1814
  return source.tag;
1881
1815
  }
1882
1816
  if (isModuleTag(source)) {
@@ -1885,7 +1819,7 @@ function useLocalModule(source, second) {
1885
1819
  return null;
1886
1820
  }, [source]);
1887
1821
  const def = import_react8.default.useMemo(() => {
1888
- if (Logix8.Module.is(source) || isModuleTag(source)) {
1822
+ if (Logix9.Module.is(source) || isModuleTag(source)) {
1889
1823
  return source;
1890
1824
  }
1891
1825
  return void 0;
@@ -1913,7 +1847,7 @@ function useLocalModule(source, second) {
1913
1847
  return createModuleTagFactory(moduleTag, moduleOptions);
1914
1848
  }
1915
1849
  const factoryFn = source;
1916
- return (scope) => factoryFn().pipe(import_effect9.Scope.extend(scope));
1850
+ return (scope) => factoryFn().pipe(import_effect8.Scope.extend(scope));
1917
1851
  }, [isModule2, moduleTag, source, moduleOptions]);
1918
1852
  const moduleRuntime = cache.readSync(key, factory, void 0, ownerId, {
1919
1853
  entrypoint: "react.useLocalModule",
@@ -1973,9 +1907,9 @@ function createModuleTagFactory(module2, options) {
1973
1907
  throw new Error("useLocalModule(module, options) \u9700\u8981\u63D0\u4F9B initial \u72B6\u6001");
1974
1908
  }
1975
1909
  const logics = options.logics ?? [];
1976
- return (scope) => import_effect9.Layer.buildWithScope(module2.live(options.initial, ...logics), scope).pipe(
1977
- import_effect9.Effect.map((context) => {
1978
- const runtime = import_effect9.Context.get(context, module2);
1910
+ return (scope) => import_effect8.Layer.buildWithScope(module2.live(options.initial, ...logics), scope).pipe(
1911
+ import_effect8.Effect.map((context) => {
1912
+ const runtime = import_effect8.Context.get(context, module2);
1979
1913
  return runtime;
1980
1914
  })
1981
1915
  );
@@ -1983,12 +1917,12 @@ function createModuleTagFactory(module2, options) {
1983
1917
 
1984
1918
  // src/internal/hooks/useLayerModule.ts
1985
1919
  var import_react9 = __toESM(require("react"), 1);
1986
- var import_effect10 = require("effect");
1920
+ var import_effect9 = require("effect");
1987
1921
  function useLayerModule(module2, layer, deps = []) {
1988
1922
  const factory = import_react9.default.useCallback(
1989
- () => import_effect10.Layer.build(layer).pipe(
1990
- import_effect10.Effect.scoped,
1991
- import_effect10.Effect.map((context) => import_effect10.Context.get(context, module2))
1923
+ () => import_effect9.Layer.build(layer).pipe(
1924
+ import_effect9.Effect.scoped,
1925
+ import_effect9.Effect.map((context) => import_effect9.Context.get(context, module2))
1992
1926
  ),
1993
1927
  // layer/module are typically constants; deps lets callers opt into rebuilding when needed.
1994
1928
  [layer, module2]
@@ -2045,8 +1979,8 @@ function useImportedModule(parent, module2) {
2045
1979
 
2046
1980
  // src/internal/hooks/useProcesses.ts
2047
1981
  var import_react13 = __toESM(require("react"), 1);
2048
- var import_effect11 = require("effect");
2049
- var Logix9 = __toESM(require("@logixjs/core"), 1);
1982
+ var import_effect10 = require("effect");
1983
+ var Logix10 = __toESM(require("@logixjs/core"), 1);
2050
1984
  var ProcessSubtreeRegistry = class {
2051
1985
  constructor(runtime) {
2052
1986
  this.runtime = runtime;
@@ -2067,7 +2001,7 @@ var ProcessSubtreeRegistry = class {
2067
2001
  }
2068
2002
  return () => this.release({ key: args.key, gcTime: args.gcTime });
2069
2003
  }
2070
- const scope = import_effect11.Effect.runSync(import_effect11.Scope.make());
2004
+ const scope = import_effect10.Effect.runSync(import_effect10.Scope.make());
2071
2005
  const entry = {
2072
2006
  key: args.key,
2073
2007
  signature: args.signature,
@@ -2095,7 +2029,7 @@ var ProcessSubtreeRegistry = class {
2095
2029
  const current = this.entries.get(entry.key);
2096
2030
  if (!current || current !== entry) return;
2097
2031
  if (current.refCount > 0) return;
2098
- void this.runtime.runPromise(import_effect11.Scope.close(entry.scope, import_effect11.Exit.void)).catch(() => {
2032
+ void this.runtime.runPromise(import_effect10.Scope.close(entry.scope, import_effect10.Exit.void)).catch(() => {
2099
2033
  });
2100
2034
  this.entries.delete(entry.key);
2101
2035
  }, timeoutMs);
@@ -2112,7 +2046,7 @@ var getRegistry = (runtime) => {
2112
2046
  var stableProcessSignature = (processes) => {
2113
2047
  const ids = [];
2114
2048
  for (let i = 0; i < processes.length; i++) {
2115
- const def = Logix9.Process.getDefinition(processes[i]);
2049
+ const def = Logix10.Process.getDefinition(processes[i]);
2116
2050
  ids.push(def?.processId ?? `legacy#${i}`);
2117
2051
  }
2118
2052
  return ids.join("|");
@@ -2155,24 +2089,24 @@ function useProcesses(processes, options) {
2155
2089
  signature,
2156
2090
  gcTime,
2157
2091
  install: (scope) => {
2158
- const program = import_effect11.Effect.forEach(
2092
+ const program = import_effect10.Effect.forEach(
2159
2093
  processes,
2160
- (process) => Logix9.InternalContracts.installProcess(process, {
2094
+ (process) => Logix10.InternalContracts.installProcess(process, {
2161
2095
  scope: { type: "uiSubtree", subtreeId },
2162
2096
  enabled: true,
2163
2097
  installedAt: "uiSubtree",
2164
2098
  mode
2165
2099
  }).pipe(
2166
- import_effect11.Effect.flatMap((installation) => {
2100
+ import_effect10.Effect.flatMap((installation) => {
2167
2101
  if (installation !== void 0) {
2168
- return import_effect11.Effect.void;
2102
+ return import_effect10.Effect.void;
2169
2103
  }
2170
- return import_effect11.Effect.forkScoped(process).pipe(import_effect11.Effect.asVoid);
2104
+ return import_effect10.Effect.forkScoped(process).pipe(import_effect10.Effect.asVoid);
2171
2105
  }),
2172
- import_effect11.Effect.catchAll(() => import_effect11.Effect.forkScoped(process).pipe(import_effect11.Effect.asVoid))
2106
+ import_effect10.Effect.catchAll(() => import_effect10.Effect.forkScoped(process).pipe(import_effect10.Effect.asVoid))
2173
2107
  ),
2174
2108
  { discard: true }
2175
- ).pipe(import_effect11.Effect.provideService(import_effect11.Scope.Scope, scope));
2109
+ ).pipe(import_effect10.Effect.provideService(import_effect10.Scope.Scope, scope));
2176
2110
  void runtime.runPromise(program).catch(() => {
2177
2111
  });
2178
2112
  }