Skip to content

Commit f258bdf

Browse files
authored
feat(nanoviews): sync with updated agera
1 parent ef7e9a2 commit f258bdf

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

packages/nanoviews/src/internals/effects.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
isAccessor,
66
effect,
77
subscribe as sub,
8-
createEffectScope,
8+
deferScope,
99
getContext,
1010
run,
1111
untracked
@@ -30,10 +30,8 @@ export function subscribe<T>(
3030
}
3131
}
3232

33-
export function createEffectScopeWithContext(context = getContext()) {
34-
const effectScope = createEffectScope()
35-
36-
return ((fn, lazy) => effectScope(() => run(context, fn), lazy)) as ReturnType<typeof createEffectScope>
33+
export function createDeferScopeWithContext(context = getContext()) {
34+
return (fn => deferScope(() => run(context, fn))) as typeof deferScope
3735
}
3836

3937
export function effectScopeSwapper<T>(

packages/nanoviews/src/internals/flow/decide.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'kida'
77
import type { Child } from '../types/index.js'
88
import {
9-
createEffectScopeWithContext,
9+
createDeferScopeWithContext,
1010
effectScopeSwapper
1111
} from '../effects.js'
1212
import { createTextNode } from '../elements/text.js'
@@ -21,7 +21,7 @@ export function reactiveDecide<T>(
2121
) {
2222
const start = createTextNode()
2323
const end = createTextNode()
24-
const effectScope = createEffectScopeWithContext()
24+
const deferScope = createDeferScopeWithContext()
2525
const fragment = document.createDocumentFragment()
2626

2727
fragment.append(start, end)
@@ -35,9 +35,8 @@ export function reactiveDecide<T>(
3535
removeBetween(start, end)
3636
}
3737

38-
const runEffects = effectScope(
39-
() => insertChildBeforeAnchor(decider(condition), end),
40-
true
38+
const runEffects = deferScope(
39+
() => insertChildBeforeAnchor(decider(condition), end)
4140
)
4241

4342
// Rerender on condition change in effect

packages/nanoviews/src/internals/flow/loop.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
EmptyValue
1414
} from '../types/index.js'
1515
import {
16-
createEffectScopeWithContext,
16+
createDeferScopeWithContext,
1717
effectScopeSwapper
1818
} from '../effects.js'
1919
import { isEmpty } from '../utils.js'
@@ -258,7 +258,7 @@ export function loop(
258258
): Child {
259259
const start = createTextNode()
260260
const end = createTextNode()
261-
const effectScope = createEffectScopeWithContext()
261+
const deferScope = createDeferScopeWithContext()
262262
const fragment = document.createDocumentFragment()
263263
const blocksMap: LookupMap = new Map()
264264
const itemsList: LoopItemsList = {
@@ -279,7 +279,7 @@ export function loop(
279279
if (itemsCount && prevItemsCount) {
280280
// [...m] -> [...n]
281281
// swap
282-
return effectScope(() => {
282+
return deferScope(() => {
283283
batch(() => reconcile(
284284
itemsList,
285285
blocksMap,
@@ -289,7 +289,7 @@ export function loop(
289289
end,
290290
items
291291
))
292-
}, true)()
292+
})()
293293
}
294294

295295
const shouldRender = itemsCount || !isPlaceholder
@@ -306,7 +306,7 @@ export function loop(
306306
if (itemsCount) {
307307
// [] -> [...n]
308308
isPlaceholder = false
309-
runEffects = effectScope(() => {
309+
runEffects = deferScope(() => {
310310
reconcile(
311311
itemsList,
312312
blocksMap,
@@ -316,13 +316,12 @@ export function loop(
316316
end,
317317
items
318318
)
319-
}, true)
319+
})
320320
} else if (!isPlaceholder) {
321321
// ([...n] | []) -> []
322322
isPlaceholder = true
323-
runEffects = effectScope(
324-
() => insertChildBeforeAnchor(else_?.(), end),
325-
true
323+
runEffects = deferScope(
324+
() => insertChildBeforeAnchor(else_?.(), end)
326325
)
327326
}
328327

packages/nanoviews/src/mount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effectScope } from 'kida'
1+
import { deferScope } from 'kida'
22
import {
33
type Child,
44
type MaybeDestroy,
@@ -18,7 +18,7 @@ export function mount(app: () => Child, target: ParentNode) {
1818
target.__mp = true
1919

2020
let unmount: MaybeDestroy
21-
const start = effectScope(() => unmount = mountChild(target, app()), true)
21+
const start = deferScope(() => unmount = mountChild(target, app()))
2222
const destroy = start()
2323

2424
return () => {

todo.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
## Nanoviews
1212

13+
- fix TruthyValueOrSignal type, return signal if signal, not accessor
14+
1315
- wrap into untracked needed parts
1416
- for loop array or empty check for else
1517
- rework return slot$ to look like element/component? fn.prop is faster than {f,p}
@@ -38,6 +40,8 @@ for_($items)(
3840

3941
## 🔥🔥🔥 Query 🔥🔥🔥
4042

43+
- map data / default data
44+
4145
- hydration provider / etc?
4246
- serialize -> dehydrate / hydrate?
4347
- combine serialize + serializable?

0 commit comments

Comments
 (0)