Skip to content

refactor: general destructuring function #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2024

Conversation

LittleSound
Copy link
Member

@LittleSound LittleSound commented May 31, 2024

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
  })
})
  1. More suitable for compression
    Function parameters that are too long are not conducive to compression, because null cannot be compressed.
    image

  2. Suitable for tree shaking

Copy link

netlify bot commented May 31, 2024

Deploy Preview for vapor-template-explorer ready!

Name Link
🔨 Latest commit e5119f7
🔍 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.

Copy link

netlify bot commented May 31, 2024

Deploy Preview for vapor-repl ready!

Name Link
🔨 Latest commit e5119f7
🔍 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.

Copy link

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

@sxzz sxzz merged commit b2259a5 into main May 31, 2024
11 checks passed
@sxzz sxzz deleted the refactor/v-for-destructuring-assignment branch May 31, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants