jq79 0.7.11 → 0.7.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/README.md +1 -1
- package/dist/jq79-sw.js +3 -3
- package/dist/jq79.cjs +15 -16
- package/dist/jq79.cjs.map +1 -1
- package/dist/jq79.d.ts +1 -1
- package/dist/jq79.global.js +15 -16
- package/dist/jq79.global.js.map +1 -1
- package/dist/jq79.js +15 -16
- package/dist/jq79.js.map +1 -1
- package/dist/precompile.cjs +4 -4
- package/dist/precompile.cjs.map +1 -1
- package/dist/precompile.js +4 -4
- package/dist/precompile.js.map +1 -1
- package/dist/reactive.d.ts +1 -0
- package/dist/source.d.ts +1 -1
- package/package.json +1 -1
- package/src/jq79.ts +383 -43
- package/src/precompile.ts +1 -0
- package/src/reactive.ts +55 -1
- package/src/source.ts +9 -4
package/src/reactive.ts
CHANGED
|
@@ -249,6 +249,56 @@ const releaseAll = (effect: Effect) => {
|
|
|
249
249
|
// than left to whatever the index happens to yield
|
|
250
250
|
let effectsCreated = 0
|
|
251
251
|
|
|
252
|
+
// $batch: while it is above 0, a woken effect is queued here instead of run -
|
|
253
|
+
// once, however many writes woke it - against the effect set of the store that
|
|
254
|
+
// woke it, which is how the flush still skips one disposed in the meantime.
|
|
255
|
+
// Module-level because one change often spans two stores (a store and the one
|
|
256
|
+
// it is bridged into), and only one queue can order them.
|
|
257
|
+
// See RECORD/2026-11-12.batch.md
|
|
258
|
+
let batchDepth = 0
|
|
259
|
+
let batched: Map<Effect, Set<Effect>> | null = null
|
|
260
|
+
|
|
261
|
+
const queueBatched = (matched: Iterable<Effect>, effects: Set<Effect>) => {
|
|
262
|
+
for (const effect of matched) if (!batched!.has(effect)) batched!.set(effect, effects)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// oldest first, like runMatched. Runs with the batch still open, so what a
|
|
266
|
+
// flushed effect writes queues into the next round of this same flush rather
|
|
267
|
+
// than running mid-round - the batch settles before $batch returns
|
|
268
|
+
const flushBatched = () => {
|
|
269
|
+
for (let rounds = 0; batched!.size; rounds++) {
|
|
270
|
+
if (rounds === 100) {
|
|
271
|
+
console.error("jq79: a $batch kept waking effects for 100 rounds (an effect writes what it reads); giving up on it settling")
|
|
272
|
+
batched!.clear()
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
const woken = batched!
|
|
276
|
+
batched = new Map()
|
|
277
|
+
const ordered = Array.from(woken.keys()).sort((a, b) => a.order - b.order)
|
|
278
|
+
ordered.forEach(effect => { if (woken.get(effect)!.has(effect)) effect.run() })
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// runs `fn`, letting its writes land and notify listeners as they happen, and
|
|
283
|
+
// runs every effect they woke once, after it returns, against the final state.
|
|
284
|
+
// Nested batches flush at the outermost. A throw still flushes - the writes it
|
|
285
|
+
// made did land - and is rethrown
|
|
286
|
+
export const $batch = <T>(fn: () => T): T => {
|
|
287
|
+
if (batchDepth++ === 0) batched = new Map()
|
|
288
|
+
try {
|
|
289
|
+
return fn()
|
|
290
|
+
} finally {
|
|
291
|
+
if (batchDepth === 1) {
|
|
292
|
+
try {
|
|
293
|
+
flushBatched()
|
|
294
|
+
} finally {
|
|
295
|
+
batchDepth = 0
|
|
296
|
+
batched = null
|
|
297
|
+
}
|
|
298
|
+
} else batchDepth--
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
252
302
|
// the deps an effect has before its first run, and what indexEffect compares
|
|
253
303
|
// its first run against. Never written to - every run installs a fresh set -
|
|
254
304
|
// so one frozen instance stands in for the two empty sets each effect used to
|
|
@@ -589,6 +639,7 @@ export const $reactive = <T extends Record<string, any>>(data: T): ReactiveDeepD
|
|
|
589
639
|
// an earlier one in this same pass (a list diff tearing down the rows it just
|
|
590
640
|
// woke) must not run
|
|
591
641
|
const runMatched = (matched: Set<Effect>) => {
|
|
642
|
+
if (batchDepth) return queueBatched(matched, effects)
|
|
592
643
|
const ordered = Array.from(matched)
|
|
593
644
|
// effects are usually collected in creation order already - one node's set
|
|
594
645
|
// is filled as its effects are made, and a subtree sweep of a freshly-built
|
|
@@ -606,7 +657,10 @@ export const $reactive = <T extends Record<string, any>>(data: T): ReactiveDeepD
|
|
|
606
657
|
// a newly-created key re-runs every effect: an effect that read the
|
|
607
658
|
// name while it didn't exist couldn't track it (`with` skipped the
|
|
608
659
|
// store entirely), so dep matching would never wake it up
|
|
609
|
-
if (isNewKey)
|
|
660
|
+
if (isNewKey) {
|
|
661
|
+
if (batchDepth) queueBatched(effects, effects)
|
|
662
|
+
else effects.forEach(effect => effect.run())
|
|
663
|
+
}
|
|
610
664
|
// `effects.has` stands in for the membership check `effects.forEach` used
|
|
611
665
|
// to give for free: an effect disposed by an earlier effect in this same
|
|
612
666
|
// notify (a list diff tearing down the rows it just woke) must not run
|
package/src/source.ts
CHANGED
|
@@ -268,7 +268,7 @@ export const splitText = (template: string): TextPart[] => {
|
|
|
268
268
|
return parts
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
export const CONTROL_ATTRS = new Set([":class", ":value", ":checked", ":selected", ":if", ":elseif", ":else", ":each", ":key", ":with", ":text", ":html", ":html.allowed", ":props"])
|
|
271
|
+
export const CONTROL_ATTRS = new Set([":class", ":value", ":checked", ":selected", ":if", ":elseif", ":else", ":each", ":key", ":window", ":with", ":text", ":html", ":html.allowed", ":props"])
|
|
272
272
|
|
|
273
273
|
// a control attribute is one the static-attr loop and nested-component prop
|
|
274
274
|
// collection must skip. The set holds the fixed names; `:class.<name>` (the
|
|
@@ -352,10 +352,15 @@ export const readSetupSignature = (script: TagBlock): PropDecl[] | null => {
|
|
|
352
352
|
// says it comes from the parent, so the file's own definition of that name is
|
|
353
353
|
// deliberately not in this component's scope. The runtime reads the setup
|
|
354
354
|
// signatures with setupSignature, which warns; precompile, with readSetupSignature
|
|
355
|
-
|
|
355
|
+
// `factoryProps` lets the runtime pass its memoized reader (see factoryPropsOf)
|
|
356
|
+
export const declaredPropNames = (
|
|
357
|
+
scripts: TagBlock[],
|
|
358
|
+
signature: (script: TagBlock) => PropDecl[] | null,
|
|
359
|
+
factoryProps: (src: string) => PropDecl[] | null = parseFactoryProps,
|
|
360
|
+
): Set<string> => {
|
|
356
361
|
const names = new Set<string>()
|
|
357
362
|
scripts.forEach(script => {
|
|
358
|
-
const declarations =
|
|
363
|
+
const declarations = factoryProps(script.content) ?? signature(script)
|
|
359
364
|
declarations?.forEach(({ name }) => names.add(name))
|
|
360
365
|
})
|
|
361
366
|
return names
|
|
@@ -369,7 +374,7 @@ export const declaredPropNames = (scripts: TagBlock[], signature: (script: TagBl
|
|
|
369
374
|
// $emit, $updateModel and $slots, then $importAll. They are positional parameters, so the order is part of what
|
|
370
375
|
// precompile has to reproduce; change one side and precompiled scripts stop
|
|
371
376
|
// matching, which tests/precompile.test.ts and `npm run check:precompile` catch
|
|
372
|
-
export const SETUP_HELPER_NAMES = ["$", "$$", "$create", "$reactive", "$toRaw", "Component79", "C79"]
|
|
377
|
+
export const SETUP_HELPER_NAMES = ["$", "$$", "$create", "$reactive", "$toRaw", "$batch", "Component79", "C79"]
|
|
373
378
|
export const INSTANCE_HELPER_NAMES = ["$mounted", "$destroyed", "$attached", "$detached", "$computed", "$self", "$$self", "$emit", "$updateModel", "$slots", "$importAll"]
|
|
374
379
|
|
|
375
380
|
// the global a precompiled script leaves its functions on, for the runtime to
|