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

proxy method not properly passing array return parameters #87

Closed
dimaf opened this issue Nov 8, 2011 · 5 comments
Closed

proxy method not properly passing array return parameters #87

dimaf opened this issue Nov 8, 2011 · 5 comments

Comments

@dimaf
Copy link

dimaf commented Nov 8, 2011

Hi,
I think there is a problem with proxy method. If I call proxy with multiple callback functions that return array back, that array is not properly passed to the next callback function. Here is short example that demonstrates the problem

    test:function (){
        this.run(['a','b','c'],this.proxy(["call1","call2"]));
    },
    run:function(arr,callback){
        callback(arr);
    },
    call1:function(arr){
        steal.dev.log("array length: "+arr.length);
        return arr;
    },
    call2:function(arr){
        steal.dev.log("array length: "+arr.length);
        return arr;
    },

If you run "test" function
The output is
steal.js INFO: array length: 3
steal.js INFO: array length: 1

Where I'd expect to see in both cases Length 3.

I tried to change in class.js

if ( f < length - 1 ) {
    cur = !isArray(cur) || cur._use_call ? [cur] : cur
}

to

if ( f < length - 1 ) {
    cur = [cur];
}

That fixed the issue and everything still seems to work.
Are there any special reasons for that !isArray(cur) || cur._use_call condition?
after all apply always wants to have a array of arguments.

This problem is also now causing Model to fail when using following config for ajax call
....
success: this.proxy(['models',success]),
...
I saw, since few days this line is comented out in model.js

//res._use_call = true; //so we don't call next function with all of these

Regards,
Dmytro

@justinbmeyer
Copy link
Member

You have to return [arr]. Just make it return an array of your array.

@dimaf
Copy link
Author

dimaf commented Nov 8, 2011

yes i saw that comment to proxy method
but this seems strange to me, since now my function needs to know in which context it's being called. if somewhere else i want to call the same function directly it will not be very clean.

But actually how i came to this problem is primary that models method is not working anymore
in such scenario:
success: this.proxy(['models',success]),

i saw in commit 92d8f88
you've commented this line out
// res._use_call = true; //so we don't call next function with all of these
and models method does not wrap the output into an additional array so when i call multiple callbacks they do not pass data properly

so either proxy needs to be fixed or that commented out line should be enabled again

@justinbmeyer
Copy link
Member

you should no longer be using this.proxy(['models',success]) like that anymore, instead you should be setting the dataType to:

"json recipe.models"

@justinbmeyer
Copy link
Member

btw, was that documented anywhere to use it like that? I've tried to clean them all from the docs.

@dimaf
Copy link
Author

dimaf commented Nov 9, 2011

Yes in new code we use either simple model definitions or properly setting type as you mentioned in the previous post, and everything works fine

it's just the old code stopped working now after that commit, so I was wondering why

-----Original Message-----
From: Justin Meyer [mailto:reply@reply.github.com]
Sent: Mittwoch, 9. November 2011 00:54
To: Khaynatskyy, Dmytro
Subject: Re: [jquerymx] proxy method not properly passing array return parameters (#87)

btw, was that documented anywhere to use it like that? I've tried to clean them all from the docs.


Reply to this email directly or view it on GitHub:
#87 (comment)

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