export function render(_ctx) {
const n0 = _createFor(() => (_ctx.list), _withDestructure(([[id, ...other], index]) => [id, other, index], (_ctx0) => {
const n2 = t0()
- _renderEffect(() => _setText(n2, _ctx0[0] + _ctx0[1] + _ctx0[2]))
+ _renderEffect(() => _setText(n2, _ctx0[0].value + _ctx0[1].value + _ctx0[2].value))
return n2
}), ([id, ...other], index) => (id))
return n0
export function render(_ctx) {
const n0 = _createFor(() => (_ctx.items), (_ctx0) => {
const n2 = t0()
- _delegate(n2, "click", () => $event => (_ctx.remove(_ctx0[0])))
- _renderEffect(() => _setText(n2, _ctx0[0]))
+ _delegate(n2, "click", () => $event => (_ctx.remove(_ctx0[0].value)))
+ _renderEffect(() => _setText(n2, _ctx0[0].value))
return n2
}, (item) => (item.id))
return n0
export function render(_ctx) {
const n0 = _createFor(() => (_ctx.items), (_ctx0) => {
const n2 = t0()
- _renderEffect(() => _setDynamicProp(n2, "item", _ctx0[0]))
- _renderEffect(() => _setDynamicProp(n2, "index", _ctx0[1]))
+ _renderEffect(() => _setDynamicProp(n2, "item", _ctx0[0].value))
+ _renderEffect(() => _setDynamicProp(n2, "index", _ctx0[1].value))
return n2
})
return n0
export function render(_ctx) {
const n0 = _createFor(() => (_ctx.list), (_ctx0) => {
const n5 = t1()
- const n2 = _createFor(() => (_ctx0[0]), (_ctx1) => {
+ const n2 = _createFor(() => (_ctx0[0].value), (_ctx1) => {
const n4 = t0()
- _renderEffect(() => _setText(n4, _ctx1[0]+_ctx0[0]))
+ _renderEffect(() => _setText(n4, _ctx1[0].value+_ctx0[0].value))
return n4
})
_insert(n2, n5)
export function render(_ctx) {
const n0 = _createFor(() => (_ctx.list), _withDestructure(([{ id, ...other }, index]) => [id, other, index], (_ctx0) => {
const n2 = t0()
- _renderEffect(() => _setText(n2, _ctx0[0] + _ctx0[1] + _ctx0[2]))
+ _renderEffect(() => _setText(n2, _ctx0[0].value + _ctx0[1].value + _ctx0[2].value))
return n2
}), ({ id, ...other }, index) => (id))
return n0
export function render(_ctx) {
const n0 = _createFor(() => (_ctx.list), _withDestructure(([{ foo = bar, baz: [qux = quux] }]) => [foo, qux], (_ctx0) => {
const n2 = t0()
- _renderEffect(() => _setText(n2, _ctx0[0] + _ctx.bar + _ctx.baz + _ctx0[1] + _ctx.quux))
+ _renderEffect(() => _setText(n2, _ctx0[0].value + _ctx.bar + _ctx.baz + _ctx0[1].value + _ctx.quux))
return n2
}))
return n0
)
expect(code).matchSnapshot()
expect(code).contains(`_createFor(() => (_ctx.list), (_ctx0) => {`)
- expect(code).contains(`_createFor(() => (_ctx0[0]), (_ctx1) => {`)
- expect(code).contains(`_ctx1[0]+_ctx0[0]`)
+ expect(code).contains(`_createFor(() => (_ctx0[0].value), (_ctx1) => {`)
+ expect(code).contains(`_ctx1[0].value+_ctx0[0].value`)
expect(ir.template).toEqual(['<span></span>', '<div></div>'])
expect(ir.block.operation).toMatchObject([
{
)
expect(code).matchSnapshot()
expect(code).contains(`([{ id, ...other }, index]) => [id, other, index]`)
- expect(code).contains(`_ctx0[0] + _ctx0[1] + _ctx0[2]`)
+ expect(code).contains(`_ctx0[0].value + _ctx0[1].value + _ctx0[2].value`)
expect(ir.block.operation[0]).toMatchObject({
type: IRNodeTypes.FOR,
source: {
)
expect(code).matchSnapshot()
expect(code).contains(`([[id, ...other], index]) => [id, other, index]`)
- expect(code).contains(`_ctx0[0] + _ctx0[1] + _ctx0[2]`)
+ expect(code).contains(`_ctx0[0].value + _ctx0[1].value + _ctx0[2]`)
expect(ir.block.operation[0]).toMatchObject({
type: IRNodeTypes.FOR,
source: {
expect(code).matchSnapshot()
expect(code).contains(`([{ foo = bar, baz: [qux = quux] }]) => [foo, qux]`)
expect(code).contains(
- `_ctx0[0] + _ctx.bar + _ctx.baz + _ctx0[1] + _ctx.quux`,
+ `_ctx0[0].value + _ctx.bar + _ctx.baz + _ctx0[1].value + _ctx.quux`,
)
expect(ir.block.operation[0]).toMatchObject({
type: IRNodeTypes.FOR,
if (context.options.prefixIdentifiers) {
propsName = `_ctx${depth}`
Array.from(idsOfValue).forEach(
- (id, idIndex) => (idMap[id] = `${propsName}[${idIndex}]`),
+ (id, idIndex) => (idMap[id] = `${propsName}[${idIndex}].value`),
)
- if (rawKey) idMap[rawKey] = `${propsName}[${idsOfValue.size}]`
- if (rawIndex) idMap[rawIndex] = `${propsName}[${idsOfValue.size + 1}]`
+ if (rawKey) idMap[rawKey] = `${propsName}[${idsOfValue.size}].value`
+ if (rawIndex) idMap[rawIndex] = `${propsName}[${idsOfValue.size + 1}].value`
} else {
propsName = `[${[rawValue || ((rawKey || rawIndex) && '_'), rawKey || (rawIndex && '__'), rawIndex].filter(Boolean).join(', ')}]`
}
state => {
const span = document.createElement('li')
renderEffect(() => {
- const [item, key, index] = state
+ const [{ value: item }, { value: key }, { value: index }] = state
span.innerHTML = `${key}. ${item.name}`
// index should be undefined if source is not an object
state => {
const span = document.createElement('li')
renderEffect(() => {
- const [item, key, index] = state
+ const [{ value: item }, { value: key }, index] = state
span.innerHTML = `${key}. ${item}`
// index should be undefined if source is not an object
- expect(index).toBe(undefined)
+ expect(index.value).toBe(undefined)
})
return span
},
state => {
const span = document.createElement('li')
renderEffect(() => {
- const [item, key, index] = state
+ const [{ value: item }, { value: key }, { value: index }] = state
span.innerHTML = `${key}${index}. ${item}`
expect(index).not.toBe(undefined)
})
const { host } = define(() => {
const n1 = createFor(
() => list.value,
- withDestructure(
- state => {
- const [{ name }, key, index] = state
- return [name, key, index]
- },
- state => {
- const span = document.createElement('li')
- renderEffect(() => {
- const [name, key, index] = state
- span.innerHTML = `${key}. ${name}`
-
- // index should be undefined if source is not an object
- expect(index).toBe(undefined)
- })
- return span
- },
- ),
+ state => {
+ const span = document.createElement('li')
+ renderEffect(() => {
+ const [
+ {
+ value: { name },
+ },
+ { value: key },
+ index,
+ ] = state
+ span.innerHTML = `${key}. ${name}`
+ // index should be undefined if source is not an object
+ expect(index.value).toBe(undefined)
+ })
+ return span
+ },
item => item.name,
)
return n1
state => {
const span = document.createElement('li')
renderEffect(() => {
- const [item, key, index] = state
+ const [{ value: item }, { value: key }, { value: index }] = state
span.innerHTML = `${key}. ${item.name}`
// index should be undefined if source is not an object
type ShallowRef,
effectScope,
isReactive,
- proxyRefs,
shallowRef,
triggerRef,
} from '@vue/reactivity'
/*! #__NO_SIDE_EFFECTS__ */
export const createFor = (
src: () => Source,
- renderItem: (block: any) => Block,
+ renderItem: (block: ForBlock['state']) => Block,
getKey?: (item: any, key: any, index?: number) => any,
getMemo?: (item: any, key: any, index?: number) => any[],
hydrationNode?: Node,
memo: getMemo && getMemo(item, key, index),
[fragmentKey]: true,
})
- block.nodes = scope.run(() => renderItem(proxyRefs(state)))!
+ block.nodes = scope.run(() => renderItem(state))!
// TODO v-memo
// if (getMemo) block.update()