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

Make the resolved data available when using can.view #209

Closed
basememara opened this issue Dec 14, 2012 · 1 comment
Closed

Make the resolved data available when using can.view #209

basememara opened this issue Dec 14, 2012 · 1 comment
Assignees
Labels
Milestone

Comments

@basememara
Copy link

An extra callback parameter was provided in 1.1.3 for can.view.render, but this is not working for can.view.

For example, data is defined here:

        can.view.render('dummyEJS', {
            user: User.findOne({id: 1})
        }).then(function(frag, data) {
            //data is defined
        });

However, data is undefined here:

        can.view('dummyEJS', {
            user: User.findOne({id: 1})
        }).then(function(frag, data) {
            //data is undefined
        });

The problem in the source seems to be that you can't just pipe deferreds that resolve with more than one argument.

A jsFiddle sample can be seen here: http://jsfiddle.net/basememara/j9XSw/7/
Related issue can be seen here: #183

@ghost ghost assigned daffl Dec 19, 2012
@rjgotten
Copy link

The problem in the source seems to be that you can't just pipe deferreds that resolve with more than one argument.

Yes you can. It just requires that you explicitly create a new Deferred instance and call resolveWith or rejectWith on this new instance before returning it as the result value.

deferred.pipe(
  function(){ return can.Deferred().resolveWith( this, can.makeArray( arguments )) },
  function(){ return can.Deferred().rejectWith ( this, can.makeArray( arguments )) }
)

It's a bit more verbose, but no more expensive than what the underlying library's pipe method would be doing under the hood when it gets back a value that is not already a promise...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants