Skip to content

Commit

Permalink
Backporting stache binding fix for special values. #2370 (#2481)
Browse files Browse the repository at this point in the history
* Backporting stache binding fix for special values. #2370

* Fix git merge conflict
  • Loading branch information
bmomberger-bitovi authored and daffl committed Sep 15, 2016
1 parent c75da90 commit 5a82dcf
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 60 deletions.
46 changes: 22 additions & 24 deletions view/bindings/bindings.js
Expand Up @@ -259,17 +259,36 @@ steal("can/util",
expr = new expression.Call(expr, defaultArgs, {} );
}

// make a scope with these things just under

var localScope = data.scope.add({
"@element": $el,
"@event": ev,
"@viewModel": viewModel,
"@scope": data.scope,
"@context": data.scope._context,

"%element": this,
"$element": $el,
"%event": ev,
"%viewModel": viewModel,
"%scope": data.scope,
"%context": data.scope._context
},{
notContext: true
});

// We grab the first item and treat it as a method that
// we'll call.
var scopeData = data.scope.read(expr.methodExpr.key, {
var scopeData = localScope.read(expr.methodExpr.key, {
isArgument: true
});

// We break out early if the first argument isn't available
// anywhere.

if (!scopeData.value) {
scopeData = data.scope.read(expr.methodExpr.key, {
scopeData = localScope.read(expr.methodExpr.key, {
isArgument: true
});

Expand All @@ -282,28 +301,7 @@ steal("can/util",

return null;
}



// make a scope with these things just under

var localScope = data.scope.add({
"@element": $el,
"@event": ev,
"@viewModel": viewModel,
"@scope": data.scope,
"@context": data.scope._context,

"%element": this,
"$element": $el,
"%event": ev,
"%viewModel": viewModel,
"%scope": data.scope,
"%context": data.scope._context
},{
notContext: true
});


var args = expr.args(localScope, null)();


Expand Down
92 changes: 56 additions & 36 deletions view/bindings/bindings_test.js
Expand Up @@ -1978,42 +1978,42 @@ steal("can/view/bindings", "can/map", "can/test", "can/component", "can/view/mus
});

test('previously non-existing select value gets selected from a list when it is added (#1762)', function() {
var template = can.view.stache('<select {($value)}="{person}">' +
'<option></option>' +
'{{#each people}}<option value="{{.}}">{{.}}</option>{{/each}}' +
'</select>' +
'<input type="text" size="5" {($value)}="person">'
);

var people = new can.List([
"Alexis",
"Mihael",
"Curtis",
"David"
]);

var vm = new can.Map({
person: 'Brian',
people: people
});

stop();
vm.bind('person', function(ev, newVal, oldVal) {
ok(false, 'person attribute should not change');
});

var frag = template(vm);

equal(vm.attr('person'), 'Brian', 'Person is still set');

setTimeout(function() {
people.push('Brian');
setTimeout(function() {
var select = frag.firstChild;
ok(select.lastChild.selected, 'New child should be selected');
start();
}, 20);
}, 20);
var template = can.view.stache('<select {($value)}="{person}">' +
'<option></option>' +
'{{#each people}}<option value="{{.}}">{{.}}</option>{{/each}}' +
'</select>' +
'<input type="text" size="5" {($value)}="person">'
);

var people = new can.List([
"Alexis",
"Mihael",
"Curtis",
"David"
]);

var vm = new can.Map({
person: 'Brian',
people: people
});

stop();
vm.bind('person', function(ev, newVal, oldVal) {
ok(false, 'person attribute should not change');
});

var frag = template(vm);

equal(vm.attr('person'), 'Brian', 'Person is still set');

setTimeout(function() {
people.push('Brian');
setTimeout(function() {
var select = frag.firstChild;
ok(select.lastChild.selected, 'New child should be selected');
start();
}, 20);
}, 20);
});

test("one-way <select> bindings keep value if options are replaced (#1762)", function(){
Expand Down Expand Up @@ -2395,4 +2395,24 @@ steal("can/view/bindings", "can/map", "can/test", "can/component", "can/view/mus
ok(vm.attr("compute").isComputed, "Back to being a compute");
});

test("special values get called", function(assert) {
expect(1);
stop();

can.Component.extend({
tag: 'ref-syntax',
viewModel: new can.Map({
method: function() {
assert.ok(true, "method called");
start();
}
})
});

can.append(
can.$("#qunit-fixture"),
can.stache("<ref-syntax ($inserted)=\"%viewModel.method()\">" +
"</ref-syntax>")({})
);
});
});

0 comments on commit 5a82dcf

Please sign in to comment.