Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-stache-bindings

Package Overview
Dependencies
Maintainers
9
Versions
219
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-stache-bindings - npm Package Compare versions

Comparing version 3.5.0-pre.0 to 3.5.0-pre.1

46

can-stache-bindings.js

@@ -179,3 +179,6 @@ // # can-stache-bindings.js

alreadyUpdatedChild: true,
nodeList: tagData.parentNodeList
nodeList: tagData.parentNodeList,
// force viewModel bindings in cases when it is ambiguous whether you are binding
// on viewModel or an attribute (:to, :from, :bind)
favorViewModel: true
});

@@ -269,3 +272,6 @@

}
var viewModel = canViewModel(el),
var viewModel,
getViewModel = function() {
return viewModel || (viewModel = canViewModel(el));
},
semaphore = {},

@@ -276,3 +282,4 @@ teardown;

// that parent and child sync values properly.
var twoWay = bindingsRegExp.exec(attrData.attributeName)[1];
var legacyBindings = bindingsRegExp.exec(attrData.attributeName);
var twoWay = legacyBindings && legacyBindings[1];

@@ -288,5 +295,3 @@ // Setup binding

semaphore: semaphore,
getViewModel: function() {
return viewModel;
},
getViewModel: getViewModel,
syncChildWithParent: twoWay

@@ -319,5 +324,3 @@ });

semaphore: semaphore,
getViewModel: function() {
return viewModel;
},
getViewModel: getViewModel,
// always update the viewModel accordingly.

@@ -598,2 +601,5 @@ initializeValues: true,

viewCallbacks.attr(/^\{[^\}]+\}$/, behaviors.data);
viewCallbacks.attr(/[\w\.]+:to/, behaviors.data);
viewCallbacks.attr(/[\w\.]+:from/, behaviors.data);
viewCallbacks.attr(/[\w\.]+:bind/, behaviors.data);

@@ -624,2 +630,13 @@ // `*ref-export` shorthand.

var getObservableFrom = {
// ### getObservableFrom.viewModelOrAttribute
viewModelOrAttribute: function(el, scope, vmNameOrProp, bindingData, mustBeSettable, stickyCompute, event) {
var viewModel = domData.get.call(el, 'viewModel');
// if we have a viewModel, use it; otherwise, setup attribute binding
if (viewModel) {
return this.viewModel.apply(this, arguments);
} else {
return this.attribute.apply(this, arguments);
}
},
// ### getObservableFrom.scope

@@ -858,3 +875,3 @@ // Returns a compute from the scope. This handles expressions like `someMethod(.,1)`.

// If undefined is return, there is no binding.
var getBindingInfo = function(node, attributeViewModelBindings, templateType, tagName) {
var getBindingInfo = function(node, attributeViewModelBindings, templateType, tagName, favorViewModel) {

@@ -871,3 +888,3 @@ var bindingInfo,

parent: "scope",
child: "viewModel",
child: favorViewModel ? "viewModel" : "viewModelOrAttribute",
childToParent: false,

@@ -885,3 +902,3 @@ parentToChild: true,

parent: "scope",
child: "viewModel",
child: favorViewModel ? "viewModel" : "viewModelOrAttribute",
childToParent: true,

@@ -899,3 +916,3 @@ parentToChild: false,

parent: "scope",
child: "viewModel",
child: favorViewModel ? "viewModel" : "viewModelOrAttribute",
childToParent: true,

@@ -911,3 +928,2 @@ parentToChild: true,

// Does this match the new binding syntax?

@@ -1029,3 +1045,3 @@ var matches = attributeName.match(bindingsRegExp);

// Get information about the binding.
var bindingInfo = getBindingInfo(node, bindingData.attributeViewModelBindings, bindingData.templateType, el.nodeName.toLowerCase());
var bindingInfo = getBindingInfo(node, bindingData.attributeViewModelBindings, bindingData.templateType, el.nodeName.toLowerCase(), bindingData.favorViewModel);
if(!bindingInfo) {

@@ -1032,0 +1048,0 @@ return;

{
"name": "can-stache-bindings",
"version": "3.5.0-pre.0",
"version": "3.5.0-pre.1",
"description": "Default binding syntaxes for can-stache",

@@ -5,0 +5,0 @@ "homepage": "http://canjs.com",

@@ -15,2 +15,3 @@ var QUnit = require("steal-qunit");

var DefineMap = require("can-define/map/map");
var canEvent = require("can-event");

@@ -166,47 +167,6 @@ function afterMutation(cb) {

test("getBindingInfo", function(){
var info;
// info = stacheBindings.getBindingInfo({name: "{$foo-ed}", value: "bar"});
// deepEqual(info, {
// parent: "scope",
// child: "attribute",
// childToParent: false,
// parentToChild: true,
// parentName: "bar",
// childName: "foo-ed",
// bindingAttributeName: "{$foo-ed}",
// initializeValues: true,
// syncChildWithParent: false
// }, "new el binding");
//
// info = stacheBindings.getBindingInfo({name: "{($foo-ed)}", value: "bar"});
// deepEqual(info, {
// parent: "scope",
// child: "attribute",
// childToParent: true,
// parentToChild: true,
// parentName: "bar",
// childName: "foo-ed",
// bindingAttributeName: "{($foo-ed)}",
// initializeValues: true,
// syncChildWithParent: true
// }, "new el binding");
//
// info = stacheBindings.getBindingInfo({name: "{^$foo-ed}", value: "bar"});
// deepEqual(info, {
// parent: "scope",
// child: "attribute",
// childToParent: true,
// parentToChild: false,
// parentName: "bar",
// childName: "foo-ed",
// bindingAttributeName: "{^$foo-ed}",
// initializeValues: true,
// syncChildWithParent: false
// }, "new el binding");
//
// // vm based
info = stacheBindings.getBindingInfo({name: "foo-ed:from", value: "bar"});
var info = stacheBindings.getBindingInfo({name: "foo-ed:from", value: "bar"});
deepEqual(info, {
parent: "scope",
child: "viewModel",
child: "viewModelOrAttribute",
parentToChild: true,

@@ -224,3 +184,3 @@ childToParent: false,

parent: "scope",
child: "viewModel",
child: "viewModelOrAttribute",
parentToChild: true,

@@ -238,3 +198,41 @@ childToParent: true,

parent: "scope",
child: "viewModelOrAttribute",
parentToChild: false,
childToParent: true,
childName: "fooEd",
parentName: "bar",
bindingAttributeName: "foo-ed:to",
initializeValues: true,
syncChildWithParent: false
}, "new el binding");
info = stacheBindings.getBindingInfo({name: "foo-ed:from", value: "bar"}, null, null, null, true);
deepEqual(info, {
parent: "scope",
child: "viewModel",
parentToChild: true,
childToParent: false,
childName: "fooEd",
parentName: "bar",
bindingAttributeName: "foo-ed:from",
initializeValues: true,
syncChildWithParent: false
}, "new vm binding");
info = stacheBindings.getBindingInfo({name: "foo-ed:bind", value: "bar"}, null, null, null, true);
deepEqual(info, {
parent: "scope",
child: "viewModel",
parentToChild: true,
childToParent: true,
childName: "fooEd",
parentName: "bar",
bindingAttributeName: "foo-ed:bind",
initializeValues: true,
syncChildWithParent: true
}, "new el binding");
info = stacheBindings.getBindingInfo({name: "foo-ed:to", value: "bar"}, null, null, null, true);
deepEqual(info, {
parent: "scope",
child: "viewModel",
parentToChild: false,

@@ -248,5 +246,84 @@ childToParent: true,

}, "new el binding");
});
test("value:from", function() {
var template = stache("<input value:from='age'/>");
var map = new SimpleMap({});
var frag = template(map);
var ta = this.fixture;
ta.appendChild(frag);
var input = ta.getElementsByTagName("input")[0];
equal(input.value, "", "input value set correctly if key does not exist in map");
map.attr("age", "30");
equal(input.value, "30", "input value set correctly");
map.attr("age", "31");
equal(input.value, "31", "input value update correctly");
input.value = "32";
canEvent.trigger.call(input, "change");
equal(map.attr("age"), "31", "NOT updated from input");
});
test("value:to", function() {
var template = stache("<input value:to='age'/>");
var map = new SimpleMap({});
var frag = template(map);
var ta = this.fixture;
ta.appendChild(frag);
var input = ta.getElementsByTagName("input")[0];
input.value = "32";
canEvent.trigger.call(input, "change");
equal(map.attr("age"), "32", "updated from input");
map.attr("age", "30");
equal(input.value, "32", "input value NOT updated");
});
test("value:bind", function() {
var template = stache("<input value:bind='age'/>");
var map = new SimpleMap({});
var frag = template(map);
var ta = this.fixture;
ta.appendChild(frag);
var input = ta.getElementsByTagName("input")[0];
equal(input.value, "", "input value set correctly if key does not exist in map");
map.attr("age", "30");
equal(input.value, "30", "input value set correctly");
map.attr("age", "31");
equal(input.value, "31", "input value update correctly");
input.value = "32";
canEvent.trigger.call(input, "change");
equal(map.attr("age"), "32", "updated from input");
});
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc