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

createInstance not calling the function #14

Open
marius-c opened this issue Sep 17, 2019 · 7 comments
Open

createInstance not calling the function #14

marius-c opened this issue Sep 17, 2019 · 7 comments

Comments

@marius-c
Copy link

Hello,

I'm doing something wrong and I'm unable to figure it out.

async function fetchVideos(opts) {
    let data = Vue.axios.get('videos', { params: opts })
        .then(response => response.data)

    return {
        total: data.length,
        data: data
    };
}
createResource('videos', fetchVideos)

did a test in a component mounted()

createInstance('videos', {
                page: 1,
                pageSize: 10,
                args() {
                    return { sort: 'likes'}
                }
})

the above doesn't produce any call to the fetchVideos function, but if I do

resource('videos').fetchRange({page: 1, pageSize: 20})

it gets called. what am I missing ?

@MaxGfeller
Copy link
Contributor

Hi @marius-c! The createInstance can only be used for computed properties, like this:

export default {
  computed: {
    videos: createInstance('videos', { page: 1, pageSize: 10 })
  }
}

Hope that helps!

@marius-c
Copy link
Author

marius-c commented Sep 18, 2019

For some reason it doesn't play well with

vue-class-component computed properties, any idea why ?
https://github.com/vuejs/vue-class-component

@MaxGfeller
Copy link
Contributor

I haven't used vue-class-component before, so i wouldn't know. Could you maybe provide a small reproducible example?

@marius-c
Copy link
Author

I will try to create an example as soon as I can. It seems that in vue-class-component, when defining a computed property you actually define a getter:
https://github.com/vuejs/vue-class-component/blob/master/dist/vue-class-component.common.js#L170

not sure if that helps ( saw that you are adding some properties on that computed which wont work in case of a getter )

@MaxGfeller
Copy link
Contributor

I think the issue may be that createInstance returns a function, which then returns the Proxy object with get and set. I honestly don't know anymore why we had to use a function, but we should check if that is still needed and if it'd work just returning the Proxy object.

@Mboulianne
Copy link

@marius-c
get something() { return createInstance(...).bind(this)(); }

@cconcha
Copy link

cconcha commented Jun 22, 2021

Hey any updates on this please?
I can't get createInstance to work on my class component
Cheers

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

4 participants