@fictjs/runtime 0.0.12 → 0.0.13
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.cjs +2330 -3203
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -141
- package/dist/index.d.ts +7 -141
- package/dist/index.dev.js +2526 -2836
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +2331 -3197
- package/dist/index.js.map +1 -1
- package/package.json +1 -6
- package/src/binding.ts +25 -422
- package/src/constants.ts +368 -344
- package/src/cycle-guard.ts +124 -97
- package/src/dom.ts +19 -25
- package/src/effect.ts +4 -0
- package/src/hooks.ts +9 -1
- package/src/index.ts +1 -19
- package/src/lifecycle.ts +13 -2
- package/src/list-helpers.ts +6 -65
- package/src/signal.ts +59 -39
- package/dist/slim.cjs +0 -3854
- package/dist/slim.cjs.map +0 -1
- package/dist/slim.d.cts +0 -504
- package/dist/slim.d.ts +0 -504
- package/dist/slim.js +0 -3802
- package/dist/slim.js.map +0 -1
- package/src/slim.ts +0 -69
package/src/signal.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { beginFlushGuard, beforeEffectRunGuard, endFlushGuard } from './cycle-gu
|
|
|
2
2
|
import { getDevtoolsHook } from './devtools'
|
|
3
3
|
import { registerRootCleanup } from './lifecycle'
|
|
4
4
|
|
|
5
|
+
const isDev =
|
|
6
|
+
typeof __DEV__ !== 'undefined'
|
|
7
|
+
? __DEV__
|
|
8
|
+
: typeof process === 'undefined' || process.env?.NODE_ENV !== 'production'
|
|
9
|
+
|
|
5
10
|
// ============================================================================
|
|
6
11
|
// Type Definitions
|
|
7
12
|
// ============================================================================
|
|
@@ -1177,21 +1182,28 @@ export function endBatch(): void {
|
|
|
1177
1182
|
*/
|
|
1178
1183
|
export function batch<T>(fn: () => T): T {
|
|
1179
1184
|
++batchDepth
|
|
1180
|
-
let
|
|
1181
|
-
let
|
|
1185
|
+
let result!: T
|
|
1186
|
+
let error: unknown
|
|
1182
1187
|
try {
|
|
1183
|
-
|
|
1188
|
+
result = fn()
|
|
1184
1189
|
} catch (e) {
|
|
1185
|
-
|
|
1186
|
-
hasError = true
|
|
1187
|
-
throw e
|
|
1190
|
+
error = e
|
|
1188
1191
|
} finally {
|
|
1189
1192
|
--batchDepth
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
+
if (batchDepth === 0) {
|
|
1194
|
+
try {
|
|
1195
|
+
flush()
|
|
1196
|
+
} catch (flushErr) {
|
|
1197
|
+
if (error === undefined) {
|
|
1198
|
+
error = flushErr
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1193
1201
|
}
|
|
1194
1202
|
}
|
|
1203
|
+
if (error !== undefined) {
|
|
1204
|
+
throw error
|
|
1205
|
+
}
|
|
1206
|
+
return result
|
|
1195
1207
|
}
|
|
1196
1208
|
/**
|
|
1197
1209
|
* Get the current active subscriber
|
|
@@ -1335,43 +1347,51 @@ export default {
|
|
|
1335
1347
|
}
|
|
1336
1348
|
export const $state = signal as <T>(value: T) => T
|
|
1337
1349
|
|
|
1338
|
-
let devtoolsSignalId = 0
|
|
1339
|
-
let devtoolsEffectId = 0
|
|
1340
|
-
|
|
1341
1350
|
interface DevtoolsIdentifiable {
|
|
1342
1351
|
__id?: number
|
|
1343
1352
|
}
|
|
1344
1353
|
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1354
|
+
let registerSignalDevtools: (value: unknown, node: SignalNode) => number | undefined = () =>
|
|
1355
|
+
undefined
|
|
1356
|
+
let updateSignalDevtools: (node: SignalNode, value: unknown) => void = () => {}
|
|
1357
|
+
let registerEffectDevtools: (node: EffectNode) => number | undefined = () => undefined
|
|
1358
|
+
let effectRunDevtools: (node: EffectNode) => void = () => {}
|
|
1359
|
+
|
|
1360
|
+
if (isDev) {
|
|
1361
|
+
let devtoolsSignalId = 0
|
|
1362
|
+
let devtoolsEffectId = 0
|
|
1363
|
+
|
|
1364
|
+
registerSignalDevtools = (value, node) => {
|
|
1365
|
+
const hook = getDevtoolsHook()
|
|
1366
|
+
if (!hook) return undefined
|
|
1367
|
+
const id = ++devtoolsSignalId
|
|
1368
|
+
hook.registerSignal(id, value)
|
|
1369
|
+
;(node as SignalNode & DevtoolsIdentifiable).__id = id
|
|
1370
|
+
return id
|
|
1371
|
+
}
|
|
1353
1372
|
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
}
|
|
1373
|
+
updateSignalDevtools = (node, value) => {
|
|
1374
|
+
const hook = getDevtoolsHook()
|
|
1375
|
+
if (!hook) return
|
|
1376
|
+
const id = (node as SignalNode & DevtoolsIdentifiable).__id
|
|
1377
|
+
if (id) hook.updateSignal(id, value)
|
|
1378
|
+
}
|
|
1360
1379
|
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1380
|
+
registerEffectDevtools = node => {
|
|
1381
|
+
const hook = getDevtoolsHook()
|
|
1382
|
+
if (!hook) return undefined
|
|
1383
|
+
const id = ++devtoolsEffectId
|
|
1384
|
+
hook.registerEffect(id)
|
|
1385
|
+
;(node as EffectNode & DevtoolsIdentifiable).__id = id
|
|
1386
|
+
return id
|
|
1387
|
+
}
|
|
1369
1388
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1389
|
+
effectRunDevtools = node => {
|
|
1390
|
+
const hook = getDevtoolsHook()
|
|
1391
|
+
if (!hook) return
|
|
1392
|
+
const id = (node as EffectNode & DevtoolsIdentifiable).__id
|
|
1393
|
+
if (id) hook.effectRun(id)
|
|
1394
|
+
}
|
|
1375
1395
|
}
|
|
1376
1396
|
|
|
1377
1397
|
// ============================================================================
|