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

Asset support for functional components #6872

Open
gabriel4649 opened this issue Oct 21, 2017 · 13 comments
Open

Asset support for functional components #6872

gabriel4649 opened this issue Oct 21, 2017 · 13 comments

Comments

@gabriel4649
Copy link

What problem does this feature solve?

Functional components with templates allow users to improve performance without sacrificing readability or ease of use. However, currently these do not support the "components" option. This limits this feature a lot, to a very limited set of use cases.

What does the proposed API look like?

Simply support the components option just like non-functional components

@c01nd01r
Copy link

Also, how to call methods and emit events in functional components with templates?

@posva
Copy link
Member

posva commented Oct 24, 2017

You cannot, you use a regular component if you need that

@yyx990803 yyx990803 changed the title Functional components should support the "components" option Asset support for functional components Nov 2, 2017
@scottbedard
Copy link

Support for local directives would be awesome!

And @c01nd01r if you need to respond to an action, you can use plain old functions

// event handler
function onClick(context, e) {
    console.log('you clicked the div');

    // to emit an event, look at the listeners in your context
    if (context.listeners.click) {
        context.listeners.click(e);
    }
}

// component
export default {
    functional: true,
    render(h, context) {
        return <div onClick={e => onClick(context, e)}>click me</div>;
    },
};

@c01nd01r
Copy link

c01nd01r commented Dec 7, 2017

Yes, @scottbedard, thank you. I know about this, but I can't do it in a "functional" html template.

<template functional>
  <div>
    <button @click="$emit('click')">Emit click</button> <!-- error -->
    <button @click="logClick">Log click</button> <!-- ??? -->
  </div>
</template>

<script>
  import { logClick } from 'logg';
</script>

@scottbedard
Copy link

Yea, that would be great. Right now we can't really expose things to our template in a clean way. The only technique I thought of, was a prop with a default value. This works, but it looks terrible in my opinion, and unnecessary bloats the component's API.

@miljan-aleksic
Copy link

@yyx990803, are there any plans ahead about supporting local directives with functional components? It would allow, among others, to convert some more advanced components as functional where those features could be replaced by directives.

I assume there are some technical limitations about it but would like to know if it's planned, what it requires, etc. So I can at least know why I must keep using normal components, for now.

@privatenumber
Copy link
Contributor

privatenumber commented May 7, 2018

I opened a PR for supporting components in functional-components (#8143). I opened a separate issue regarding making methods accessible in functional-components (#8142); can open a PR if the feature request gets approved.

@dougalg
Copy link

dougalg commented Aug 18, 2018

What is holding up the PR? It's been almost 4 months since it was opened.

@miljan-aleksic
Copy link

I would love to see this merged.

@cdaly7
Copy link

cdaly7 commented Nov 20, 2018

Any further update on this improvement?

@Fnxxxxo
Copy link

Fnxxxxo commented Mar 26, 2019

It seems the PR is blocked since of conflicts in options interface.

@kahirokunn
Copy link

Do you have new news?
I really want to use components option with functional component.

@privatenumber
Copy link
Contributor

@kahirokunn

This will likely never get approved. In v3, functional components are getting stripped of features even more in favor of stateful components supporting everything functional components can do; basically, you'll be able to update your functional component to be stateful and you'll rarely have a need for functional components in the future.

Read the RFC here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests