vuejs / core-vapor

Vue Vapor is a variant of Vue that offers rendering without the Virtual DOM.
https://vapor-repl.netlify.app
MIT License
1.8k stars 86 forks source link

refactor: general destructuring function #221

Closed LittleSound closed 3 months ago

LittleSound commented 3 months ago

Changed the parameter destructuring of v-for to be implemented through a separate withDestructure function.

related: #204

Reasons for refactoring:

  1. Suitable for both v-for and v-slot
    
    // v-for
    const n0 = createFor(() => ctx.list, withDestructure(
    (state, [{ id, ...other }, index] = state) => [id, other, index],
    (ctx0) => {
    const n2 = t0()
    renderEffect(() => setText(n2, ctx0[0] + ctx0[1] + ctx0[2]))
    return n2
    }), ({ id, ...other }, index) => (id))

// v-slot const n0 = createComponent(Comp2, null, { default: withDestructure((props, { a, b: [[d] = a, ...c] } = props) => [a,b], (ctx0) => { const n1 = createTextNode(() => [ctx0[0] + ctx0[1]]) return n1 }) })



2. More suitable for compression
Function parameters that are too long are not conducive to compression, because `null` cannot be compressed.
![image](https://github.com/vuejs/core-vapor/assets/19204772/a7ee44de-3009-4959-9dab-2d8cb27f51d4)

3. Suitable for tree shaking
netlify[bot] commented 3 months ago

Deploy Preview for vapor-template-explorer ready!

Name Link
Latest commit e5119f733297247f9e4707d01287461a1953f547
Latest deploy log https://app.netlify.com/sites/vapor-template-explorer/deploys/66596c990e64520009a87dcb
Deploy Preview https://deploy-preview-221--vapor-template-explorer.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 3 months ago

Deploy Preview for vapor-repl ready!

Name Link
Latest commit e5119f733297247f9e4707d01287461a1953f547
Latest deploy log https://app.netlify.com/sites/vapor-repl/deploys/66596c99f211ff000880306b
Deploy Preview https://deploy-preview-221--vapor-repl.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

github-actions[bot] commented 3 months ago

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 80.1 kB 28.1 kB 24.7 kB
compiler-vapor.global.prod.js 56.9 kB (-25 B) 19.4 kB (-8 B) 17.5 kB (-12 B)
runtime-dom.global.prod.js 95.1 kB 35.8 kB 32.3 kB
runtime-vapor.global.prod.js 48.3 kB (-24 B) 18 kB (-8 B) 16.5 kB (-8 B)
vue-vapor.global.prod.js 102 kB (-49 B) 35.8 kB (-5 B) 32.2 kB (-29 B)
vue.global.prod.js 152 kB 55.1 kB 49.3 kB

Usages

Name Size Gzip Brotli
createApp 55.4 kB 21.2 kB 19.4 kB
createSSRApp 58.7 kB 22.6 kB 20.6 kB
defineCustomElement 57.7 kB 21.9 kB 20 kB
vapor 48.6 kB (-26 B) 18.1 kB (-5 B) 16.5 kB (-4 B)
overall 69.2 kB 26.2 kB 23.8 kB