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

Ability to reference <template> as Hyperscript in render() #1686

Open
amcsi opened this issue Jun 15, 2020 · 0 comments
Open

Ability to reference <template> as Hyperscript in render() #1686

amcsi opened this issue Jun 15, 2020 · 0 comments

Comments

@amcsi
Copy link

amcsi commented Jun 15, 2020

What problem does this feature solve?

Currently you have to choose between using a <template> or using a render() function. As soon as you would need to reach for something advanced that templates don't allow for, you have to toss out all the nice template code you wrote and rewrite it into more difficult-to-write-and-read render function code, even if it's just a little bit of custom render code you'd need.

It would be cool if for these cases you could mix using both and the render() function by allowing you to reference the hyperscript of the template tag.

I think my API suggestion would be a BC break, because currently render functions don't run if there's a template. So maybe as an alternative to my example below, there could be a special attribute you could give to templates so that they wouldn't prevent the render() function from running, and in addition, you could choose which template you want to reference in your render() function.

What does the proposed API look like?

<template>
  <span>Maybe a link</span>
</template>

<script>
export default {
  props: {
    href: String,
  },
  render(h) {
    // HERE is the newly proposed syntax:
    const template = this.template();

    if (!this.href) {
      // Not a link.
      return template;
    }

    // A link.
    return h('a', {attrs: { href: href }}, [template]);
  },
};
</script>

@amcsi amcsi changed the title Ability to reference template in render Ability to reference <template> as Hyperscript in render() Jun 15, 2020
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

No branches or pull requests

1 participant