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

Calling a function with parameters #2

Closed
tradingstratagem opened this issue Jul 6, 2018 · 9 comments
Closed

Calling a function with parameters #2

tradingstratagem opened this issue Jul 6, 2018 · 9 comments

Comments

@tradingstratagem
Copy link

I try to pass a parameter for the function called when clicking the button, but I figured out that this doesn't work.
Is it there any workaround in order to pass parameters to the function and still have the spinner working?

<button class="btn btn-default" @click="test(param1)" v-promise-btn>Save</button>

Thank you

@STUkh
Copy link
Owner

STUkh commented Jul 6, 2018

Please, create gist with example. Everything should be fine with your case.

@tradingstratagem
Copy link
Author

@STUkh
Copy link
Owner

STUkh commented Jul 10, 2018

@tradingstratagem your app logic a little bit incorrect. Click event should accept function that returns promise, instead of promise instance itself.

@tradingstratagem
Copy link
Author

@STUkh
Copy link
Owner

STUkh commented Jul 11, 2018

@tradingstratagem in your case, function with params should looks like this:

function test (param1) {
    // return anonymous function that will be triggered on click from view with "param1" in closure
    return function () {
        return new Promise(function (res, rej) { setTimeout(function () { res() }, 2000) });
    }
}

@tradingstratagem
Copy link
Author

I tried but nothing happens

@STUkh
Copy link
Owner

STUkh commented Jul 12, 2018

@tradingstratagem i've just tested on my own project - all works properly. Close this thread, fell free open new one with jsfiddle or jsbin example if you face this problem again.

@STUkh STUkh closed this as completed Jul 12, 2018
@SebastienTainon
Copy link

SebastienTainon commented Nov 27, 2018

Hello @STUkh @tradingstratagem

I can confirm the issue that was reported, and here is a reproducing jsfiddle: https://jsfiddle.net/rd5ef4t1/1/

I think there was a misunderstanding on the issue. Here the JSfiddle is based on the index.html/example.js files from the vue-promise-btn demo. The directive works well when the handler function doesn't need any argument. However when we pass any argument to the handler, the handler returns "undefined" instead of returning the promise, thus the directive isn't working.

It seems to me that the problem is very similar to this issue that you previously solved @STUkh vuejs/vue#7705 because when I look the generated code for my handlers, I get:

Without arguments, valid return:

on:{"click":function($event){$event.preventDefault();return dummyAsyncAction($event)}}}

With arguments, missing return:

on:{"click":function($event){$event.preventDefault();dummyAsyncAction('arg')}}}

It seems that the "return" is missing for handlers with arguments, what do you think?

@clnt clnt mentioned this issue Jan 24, 2019
STUkh pushed a commit that referenced this issue Feb 8, 2019
@STUkh
Copy link
Owner

STUkh commented Feb 28, 2019

@SebastienTainon , @tradingstratagem - you can try v2.0.0 with extended mode - it fixes a lot of issues

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

3 participants