Skip to content
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

feat(runtime-vapor): component attrs #47

Closed
wants to merge 0 commits into from
Closed

feat(runtime-vapor): component attrs #47

wants to merge 0 commits into from

Conversation

ubugeeei
Copy link
Member

@ubugeeei ubugeeei commented Dec 10, 2023

closes: #48

Summary

I have implemented attrs.
This branch is derived from the branch for implementing emits.
Please merge the emits PR first.

Points I'm unsure about

  1. inheritAttrs
    Should be inheritAttrs option is implemented?
    If it seems necessary, I'll address it in a separate PR. (I've added base issue Todo)

How to confirm the operation

Since the compiler implementation is not yet available, I have written the expected JavaScript code as the compilation result in playground/src/attrs.js.

code

import { watch } from 'vue'
import {
  children,
  on,
  ref,
  template,
  watchEffect,
  setText,
  render as renderComponent // TODO:
} from '@vue/vapor'

export default {
  props: undefined,

  setup(_, {}) {
    const count = ref(1)
    const handleClick = () => {
      count.value++
    }

    const __returned__ = { count, handleClick }

    Object.defineProperty(__returned__, '__isScriptSetup', {
      enumerable: false,
      value: true
    })

    return __returned__
  },

  render(_ctx) {
    const t0 = template('<button></button>')
    const n0 = t0()
    const {
      0: [n1]
    } = children(n0)
    on(n1, 'click', _ctx.handleClick)
    watchEffect(() => {
      setText(n1, void 0, _ctx.count)
    })

    renderComponent(
      child,
      {
        get count() {
          return _ctx.count
        }
      },
      [],
      n0
    )

    return n0
  }
}

const child = {
  setup(_, { attrs }) {
    console.log('attrs: ', attrs)
    watch(
      () => attrs.count,
      v => console.log('attrs.count changed', v)
    )

    const __returned__ = {}

    Object.defineProperty(__returned__, '__isScriptSetup', {
      enumerable: false,
      value: true
    })

    return __returned__
  },

  render(_ctx) {
    const t0 = template('<p></p>')
    const n0 = t0()
    const {
      0: [n1]
    } = children(n0)
    watchEffect(() => {
      setText(n1, void 0, _ctx.$attrs.count + ' * 2 = ' + _ctx.$attrs.count * 2)
    })
    return n0
  }
}
2023-12-10.19.23.40.mov

@ubugeeei ubugeeei marked this pull request as draft December 10, 2023 10:26
@ubugeeei
Copy link
Member Author

⚠️ Mark as draft until Emits PR is merged.

Copy link

github-actions bot commented Dec 10, 2023

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 91.1 kB 34.7 kB 31.2 kB
runtime-vapor.global.prod.js 28.3 kB (+1.15 kB) 10.8 kB (+401 B) 9.93 kB (+383 B)
vue-vapor.global.prod.js 66.9 kB (+1.15 kB) 23.3 kB (+426 B) 21 kB (+388 B)
vue.global.prod.js 148 kB 53.9 kB 48.1 kB

Usages

Name Size Gzip Brotli
createApp 51.4 kB 20 kB 18.3 kB
createSSRApp 54.7 kB 21.3 kB 19.4 kB
defineCustomElement 53.7 kB 20.8 kB 19 kB
vapor 28.4 kB (+1.15 kB) 10.9 kB (+401 B) 9.99 kB (+393 B)
overall 65.1 kB 25.1 kB 22.7 kB

@ubugeeei
Copy link
Member Author

Oh, I was under the impression that the render function would receive attrs as ctx, so I was trying to implement publicInstance, but it seems that this implementation was removed by this commit. What approach should I take for the implementation...? 🤔

efc32b7

Copy link

netlify bot commented Jan 24, 2024

Deploy Preview for vapor-repl ready!

Name Link
🔨 Latest commit d90b7c8304c771c659aefca1b62a6c4b6625339c
🔍 Latest deploy log https://app.netlify.com/sites/vapor-repl/deploys/65b6498b1f612e000860a3bf
😎 Deploy Preview https://deploy-preview-47--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.

@sxzz sxzz force-pushed the main branch 2 times, most recently from 2f9e25d to 0255505 Compare January 25, 2024 09:00
@sxzz sxzz closed this Jan 28, 2024
@sxzz sxzz reopened this Jan 28, 2024
@sxzz sxzz closed this Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pending
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Component Attrs
2 participants