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

Allow passing component instance to computed #767

Closed
MartinMalinda opened this issue Jul 18, 2021 · 2 comments
Closed

Allow passing component instance to computed #767

MartinMalinda opened this issue Jul 18, 2021 · 2 comments

Comments

@MartinMalinda
Copy link

MartinMalinda commented Jul 18, 2021

I just read this great article https://antfu.me/posts/async-with-composition-api#explicitly-bound-the-instance from @antfu and I figured it would be really nice if there was a way to pass instance also to computed.

The fallback solution in computed properties that happens when instance is missing is quite costly and so it would be nice to get around this.

https://github.com/vuejs/composition-api/blob/master/src/apis/computed.ts#L75

My usecase:

In vue-concurrency I call a function useTask which returns a reactive() object with a bunch of computed() in it. useTask is called in setup() so so far so good.

But task can create a new task instance via task.perform() which creates yet another reactive() and multiple computed(). Sometimes task.perform() is called right away in setup() but sometimes it's called later, maybe after user interaction. In that case vm is null and the fallback solution is used. The fallback solution then creates a performance overhead.

Maybe I should redesign my library not to create new computed for every task.perform(), but so far this solution was really convenient.

SInce vue 3 accepts an object as a 2nd param maybe it could be okay to allow computed(() => {}, { instance });

@antfu
Copy link
Member

antfu commented Jul 18, 2021

Maybe this would fit what you need

vuejs/rfcs#212

If not, maybe you would like to create a formal RFC to for discussion first. This plugin is aim to match with Vue 3's API design, so we will only ship feature that landed to Vue 3.

The process will be

RFC -> Vue 3 implementation -> Merged and released -> @vue/composition-api implementation

Thanks for bring it up. Closing.

@antfu antfu closed this as completed Jul 18, 2021
@MartinMalinda
Copy link
Author

If not, maybe you would like to create a formal RFC to for discussion first. This plugin is aim to match with Vue 3's API design, so we will only ship feature that landed to Vue 3.

Yeah, effectScope is nice but I can't find a way how it would solve my issue right now. I need a lower level solution. I'll think about it and I'll create an RFC.

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

2 participants