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

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

Comments

Projects
None yet
3 participants
@basememara

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

This comment has been minimized.

Show comment
Hide comment
@rjgotten

rjgotten Dec 31, 2012

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...

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...

@daffl daffl referenced this issue Dec 31, 2012

Merged

Resolve view data #220

@daffl daffl closed this in cfa0c16 Dec 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment