Skip to content

Commit

Permalink
Update compute.read to also return constructor functions. Adding anot…
Browse files Browse the repository at this point in the history
…her test for canjs#1261
  • Loading branch information
daffl committed Nov 20, 2014
1 parent cc6428b commit a373b64
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
27 changes: 27 additions & 0 deletions component/component_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1311,4 +1311,31 @@ steal("can/component", "can/view/stache" ,"can/route", function () {

});

test('scope objects with Constructor functions as properties do not get converted (#1261)', 1, function(){
stop();

var Test = can.Map.extend({
test: 'Yeah'
});

can.Component.extend({
tag:'my-app',
scope: {
MyConstruct: Test
},
events: {
'{MyConstruct} something': function() {
ok(true, 'Event got triggered');
start();
}
}
});

var frag = can.stache('<my-app></my-app>')();

// element must be inserted, otherwise attributes event will not be fired
can.append(can.$("#qunit-test-area"),frag);

can.trigger(Test, 'something');
});
});
3 changes: 2 additions & 1 deletion compute/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ steal('can/util', 'can/util/bind', 'can/util/batch', function (can, bind) {
// call that method
if (options.returnObserveMethods) {
cur = cur[reads[i]];
} else if (reads[i] === 'constructor' && prev instanceof can.Construct) {
} else if ( (reads[i] === 'constructor' && prev instanceof can.Construct) ||
(prev[reads[i]].prototype instanceof can.Construct)) {
cur = prev[reads[i]];
} else {
cur = prev[reads[i]].apply(prev, options.args || []);
Expand Down
10 changes: 9 additions & 1 deletion compute/compute_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,13 @@ steal("can/compute", "can/test", "can/map", function () {
var result = can.compute.read(parent, reads);
equal(result.value, "Justin", "The correct value is found.");
});


test("compute.read returns constructor functions instead of executing them (#1332)", function() {
var Todo = can.Map.extend({});
var parent = can.compute(new can.Map({map: { Test: Todo }}));
var reads = ["map", "Test"];

var result = can.compute.read(parent, reads);
equal(result.value, Todo, 'Got the same Todo');
});
});

0 comments on commit a373b64

Please sign in to comment.