Description
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 });