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 emits #42

Closed
wants to merge 35 commits into from
Closed

feat(runtime-vapor): component emits #42

wants to merge 35 commits into from

Conversation

ubugeeei
Copy link
Member

@ubugeeei ubugeeei commented Dec 8, 2023

Closes #41

Summary

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

Points I'm unsure about

  1. Flags related to lifecycle
    I had implemented it so that isMounted is set to false when unmounting,
    In traditional components, it seems that isUnmounted is set to true.
    Which approach should we follow for the implementation? (In this PR, I have added the isUnmounted flag.)

  2. Holding rawProps in ComponentInternalInstance
    I think we will face the same issue when implementing attr, but in emit, we need to search for handlers from user-defined raw props, not those defined as propsOption.
    In the past, raw props were held in instance.vnode.props, but at the moment, there is no implementation that handles vnode, so I am directly holding them in ComponentInternalInstance.
    Is this okay?

  3. Caching
    Similar to props, I haven't implemented caching because I don't understand how to handle it.
    Should we also implement it in Vapor Mode?

  4. Validations
    Should be emits validations are implemented?
    https://vuejs.org/guide/components/events.html#events-validation

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/emits.js.

code

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

export default {
  props: undefined,

  setup(_, {}) {
    const count = ref(1)
    const setCount = v => {
      count.value = v
    }

    const __returned__ = { count, setCount }

    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.count)
    })

    renderComponent(
      child,
      {
        get count() {
          return _ctx.count
        },
        get ['onClick:child']() {
          return _ctx.setCount
        }
      },
      [],
      n0
    )

    renderComponent(
      child,
      {
        get count() {
          return _ctx.count
        },
        get ['onClick:childOnce']() {
          return _ctx.setCount
        }
      },
      [],
      n0
    )

    return n0
  }
}

const child = {
  props: {
    count: { type: Number, default: 1 }
  },

  setup(props, { emit }) {
    const handleClick = () => {
      emit('click:child', props.count * 2)
    }

    const __returned__ = { handleClick }

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

    return __returned__
  },

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

Left button: normal emit
Right button: emit once

2023-12-10.13.38.52.mov

@ubugeeei ubugeeei added the enhancement New feature or request label Dec 8, 2023
@ubugeeei ubugeeei marked this pull request as draft December 8, 2023 15:57
Copy link

github-actions bot commented Dec 8, 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 27.6 kB (+471 B) 10.6 kB (+169 B) 9.71 kB (+161 B)
vue-vapor.global.prod.js 66.2 kB (+471 B) 23 kB (+182 B) 20.8 kB (+160 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 27.7 kB (+475 B) 10.6 kB (+167 B) 9.76 kB (+159 B)
overall 65.1 kB 25.1 kB 22.7 kB

@ubugeeei
Copy link
Member Author

ubugeeei commented Dec 8, 2023

⚠️ Mark as draft until Props PR is merged.

@ubugeeei ubugeeei mentioned this pull request Dec 8, 2023
28 tasks
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just added a playground for checking the default values.
It's not related to the content of this PR, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023-12-10.13.37.25.mov

@ubugeeei ubugeeei requested a review from sxzz December 10, 2023 04:36
@ubugeeei ubugeeei marked this pull request as ready for review December 10, 2023 04:36
@ubugeeei
Copy link
Member Author

#47 (comment)

@ubugeeei
Copy link
Member Author

ubugeeei commented Jan 3, 2024

This PR is on hold until this issue is resolved.
#84

@ubugeeei ubugeeei marked this pull request as draft January 3, 2024 12:39
@ubugeeei
Copy link
Member Author

🤷‍♂️

Run pnpm run format-check
  pnpm run format-check
  shell: /usr/bin/bash -e {0}
  env:
    PUPPETEER_SKIP_DOWNLOAD: true
    PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin

> @0.0.0-vapor format-check /home/runner/work/core-vapor/core-vapor
> prettier --check --cache .

Checking formatting...
[warn] packages/reactivity/src/ref.ts
[warn] packages/runtime-core/src/componentEmits.ts
[warn] packages/runtime-core/src/componentPublicInstance.ts
[warn] packages/runtime-vapor/src/componentEmits.ts
[warn] tsconfig.json
[warn] Code style issues found in [5](https://github.com/vuejs/core-vapor/actions/runs/7600943756/job/20699756554?pr=42#step:7:5) files. Run Prettier to fix.

Copy link

netlify bot commented Jan 24, 2024

Deploy Preview for vapor-repl ready!

Name Link
🔨 Latest commit f6e71af
🔍 Latest deploy log https://app.netlify.com/sites/vapor-repl/deploys/65b12e1ebcfe850008d9a422
😎 Deploy Preview https://deploy-preview-42--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
@sxzz
Copy link
Member

sxzz commented Jan 28, 2024

#83 (comment)

@ubugeeei ubugeeei removed the request for review from sxzz February 9, 2024 16:37
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 Emits
2 participants