Skip to content

Commit

Permalink
simplified ReturnValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyavf committed Jan 24, 2017
1 parent 5c00ac4 commit 5aa7e69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 3 additions & 4 deletions can-construct.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ assign(Construct, {
});
args = inst.setup.apply(inst, arguments);
if (args instanceof Construct.ReturnValue){
return args.initCb.apply(null, args.args);
return args.value;
}
inst.__inSetup = false;
}
Expand Down Expand Up @@ -667,9 +667,8 @@ assign(Construct, {
* ```
*/
},
ReturnValue: function(cb, args){
this.initCb = cb;
this.args = args;
ReturnValue: function(value){
this.value = value;
}
});
/**
Expand Down
8 changes: 2 additions & 6 deletions can-construct_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ QUnit.test("return alternative value simple", function(){
var Alternative = function(){};
var Base = Construct.extend({
setup: function(){
return new Construct.ReturnValue(function(){
return new Alternative();
});
return new Construct.ReturnValue( new Alternative() );
}
});
QUnit.ok(new Base() instanceof Alternative, "Should create an instance of Alternative");
Expand All @@ -249,9 +247,7 @@ QUnit.test("return alternative value on setup (full case)", function(){
console.log('[Person.setup]');
if (opts.age >= 16){
console.log('[Person.setup] >= 16');
return new Construct.ReturnValue(function(params){
return new Student(params.name, params.school);
}, [opts]);
return new Construct.ReturnValue( new Student(opts.name, opts.school) );
}
console.log('[Person.setup] < 16');
opts.isStudent = false;
Expand Down

0 comments on commit 5aa7e69

Please sign in to comment.