can-stache-bindings
Advanced tools
Comparing version 4.2.5 to 4.2.6
@@ -37,2 +37,5 @@ // # can-stache-bindings.js | ||
// Contains all of the stache bindings that will be exported. | ||
var bindings = new Map(); | ||
var onMatchStr = "on:", | ||
@@ -53,3 +56,3 @@ vmMatchStr = "vm:", | ||
var throwOnlyOneTypeOfBindingError = function(){ | ||
var throwOnlyOneTypeOfBindingError = function() { | ||
throw new Error("can-stache-bindings - you can not have contextual bindings ( this:from='value' ) and key bindings ( prop:from='value' ) on one element."); | ||
@@ -64,18 +67,24 @@ }; | ||
var isSettingOnViewModel = dataBinding.bindingInfo.parentToChild && dataBinding.bindingInfo.child === viewModelBindingStr; | ||
if(isSettingOnViewModel) { | ||
if (isSettingOnViewModel) { | ||
var bindingName = dataBinding.bindingInfo.childName; | ||
var isSettingViewModel = isSettingOnViewModel && ( bindingName === 'this' || bindingName === '.' ); | ||
var isSettingViewModel = isSettingOnViewModel && (bindingName === 'this' || bindingName === '.'); | ||
if( isSettingViewModel ) { | ||
if(bindingState.isSettingViewModel || bindingState.isSettingOnViewModel) { | ||
if (isSettingViewModel) { | ||
if (bindingState.isSettingViewModel || bindingState.isSettingOnViewModel) { | ||
throwOnlyOneTypeOfBindingError(); | ||
} else { | ||
return {isSettingViewModel: true, initialViewModelData: undefined}; | ||
return { | ||
isSettingViewModel: true, | ||
initialViewModelData: undefined | ||
}; | ||
} | ||
} else { | ||
// just setting on viewModel | ||
if(bindingState.isSettingViewModel) { | ||
if (bindingState.isSettingViewModel) { | ||
throwOnlyOneTypeOfBindingError(); | ||
} else { | ||
return {isSettingOnViewModel: true, initialViewModelData: bindingState.initialViewModelData}; | ||
return { | ||
isSettingOnViewModel: true, | ||
initialViewModelData: bindingState.initialViewModelData | ||
}; | ||
} | ||
@@ -146,3 +155,3 @@ } | ||
if(dataBinding) { | ||
if (dataBinding) { | ||
bindingsState = checkBindingState(bindingsState, dataBinding); | ||
@@ -153,7 +162,7 @@ hasDataBinding = true; | ||
// For bindings that change the viewModel, | ||
if(dataBinding.onCompleteBinding) { | ||
if (dataBinding.onCompleteBinding) { | ||
// save the initial value on the viewModel. | ||
if(dataBinding.bindingInfo.parentToChild && dataBinding.value !== undefined) { | ||
if (dataBinding.bindingInfo.parentToChild && dataBinding.value !== undefined) { | ||
if(bindingsState.isSettingViewModel) { | ||
if (bindingsState.isSettingViewModel) { | ||
// the initial data is the context | ||
@@ -172,3 +181,3 @@ bindingsState.initialViewModelData = dataBinding.value; | ||
}); | ||
if(staticDataBindingsOnly && !hasDataBinding) { | ||
if (staticDataBindingsOnly && !hasDataBinding) { | ||
return; | ||
@@ -179,3 +188,3 @@ } | ||
for(var i = 0, len = onCompleteBindings.length; i < len; i++) { | ||
for (var i = 0, len = onCompleteBindings.length; i < len; i++) { | ||
onCompleteBindings[i](); | ||
@@ -187,8 +196,8 @@ } | ||
var attributeDisposal; | ||
if(!bindingsState.isSettingViewModel) { | ||
attributeDisposal = domMutate.onNodeAttributeChange(el, function (ev) { | ||
if (!bindingsState.isSettingViewModel) { | ||
attributeDisposal = domMutate.onNodeAttributeChange(el, function(ev) { | ||
var attrName = ev.attributeName, | ||
value = el.getAttribute(attrName); | ||
if( onTeardowns[attrName] ) { | ||
if (onTeardowns[attrName]) { | ||
onTeardowns[attrName](); | ||
@@ -199,4 +208,7 @@ } | ||
if(value !== null || parentBindingWasAttribute ) { | ||
var dataBinding = makeDataBinding({name: attrName, value: value}, el, { | ||
if (value !== null || parentBindingWasAttribute) { | ||
var dataBinding = makeDataBinding({ | ||
name: attrName, | ||
value: value | ||
}, el, { | ||
templateType: tagData.templateType, | ||
@@ -213,5 +225,5 @@ scope: tagData.scope, | ||
}); | ||
if(dataBinding) { | ||
if (dataBinding) { | ||
// The viewModel is created, so call callback immediately. | ||
if(dataBinding.onCompleteBinding) { | ||
if (dataBinding.onCompleteBinding) { | ||
dataBinding.onCompleteBinding(); | ||
@@ -231,3 +243,3 @@ } | ||
} | ||
for(var attrName in onTeardowns) { | ||
for (var attrName in onTeardowns) { | ||
onTeardowns[attrName](); | ||
@@ -241,3 +253,3 @@ } | ||
data: function(el, attrData) { | ||
if(domData.get.call(el, "preventDataBindings")) { | ||
if (domData.get.call(el, "preventDataBindings")) { | ||
return; | ||
@@ -254,86 +266,91 @@ } | ||
// Setup binding | ||
var dataBinding = makeDataBinding({ | ||
name: attrData.attributeName, | ||
value: el.getAttribute(attrData.attributeName), | ||
nodeList: attrData.nodeList | ||
}, el, { | ||
templateType: attrData.templateType, | ||
scope: attrData.scope, | ||
semaphore: semaphore, | ||
getViewModel: getViewModel, | ||
syncChildWithParent: false | ||
}); | ||
// Setup binding | ||
var dataBinding = makeDataBinding({ | ||
name: attrData.attributeName, | ||
value: el.getAttribute(attrData.attributeName), | ||
nodeList: attrData.nodeList | ||
}, el, { | ||
templateType: attrData.templateType, | ||
scope: attrData.scope, | ||
semaphore: semaphore, | ||
getViewModel: getViewModel, | ||
syncChildWithParent: false | ||
}); | ||
//!steal-remove-start | ||
if(dataBinding.bindingInfo.child === "viewModel" && !domData.get(el, "viewModel")) { | ||
//!steal-remove-start | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (dataBinding.bindingInfo.child === "viewModel" && !domData.get(el, "viewModel")) { | ||
dev.warn('This element does not have a viewModel. (Attempting to bind `' + dataBinding.bindingInfo.bindingAttributeName + '="' + dataBinding.bindingInfo.parentName + '"`)'); | ||
} | ||
//!steal-remove-end | ||
} | ||
//!steal-remove-end | ||
if(dataBinding.onCompleteBinding) { | ||
dataBinding.onCompleteBinding(); | ||
} | ||
if (dataBinding.onCompleteBinding) { | ||
dataBinding.onCompleteBinding(); | ||
} | ||
var attributeListener = function (ev) { | ||
var attrName = ev.attributeName, | ||
value = el.getAttribute(attrName); | ||
var attributeListener = function(ev) { | ||
var attrName = ev.attributeName, | ||
value = el.getAttribute(attrName); | ||
if( attrName === attrData.attributeName ) { | ||
if( teardown ) { | ||
teardown(); | ||
} | ||
if (attrName === attrData.attributeName) { | ||
if (teardown) { | ||
teardown(); | ||
} | ||
if(value !== null ) { | ||
var dataBinding = makeDataBinding({name: attrName, value: value}, el, { | ||
templateType: attrData.templateType, | ||
scope: attrData.scope, | ||
semaphore: semaphore, | ||
getViewModel: getViewModel, | ||
// always update the viewModel accordingly. | ||
initializeValues: true, | ||
nodeList: attrData.nodeList, | ||
syncChildWithParent: false | ||
}); | ||
if(dataBinding) { | ||
// The viewModel is created, so call callback immediately. | ||
if(dataBinding.onCompleteBinding) { | ||
dataBinding.onCompleteBinding(); | ||
} | ||
teardown = dataBinding.onTeardown; | ||
if (value !== null) { | ||
var dataBinding = makeDataBinding({ | ||
name: attrName, | ||
value: value | ||
}, el, { | ||
templateType: attrData.templateType, | ||
scope: attrData.scope, | ||
semaphore: semaphore, | ||
getViewModel: getViewModel, | ||
// always update the viewModel accordingly. | ||
initializeValues: true, | ||
nodeList: attrData.nodeList, | ||
syncChildWithParent: false | ||
}); | ||
if (dataBinding) { | ||
// The viewModel is created, so call callback immediately. | ||
if (dataBinding.onCompleteBinding) { | ||
dataBinding.onCompleteBinding(); | ||
} | ||
teardown = dataBinding.onTeardown; | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
var tearItAllDown = function(){ | ||
if(teardown) { | ||
teardown(); | ||
teardown = undefined; | ||
} | ||
var tearItAllDown = function() { | ||
if (teardown) { | ||
teardown(); | ||
teardown = undefined; | ||
} | ||
if (removedDisposal) { | ||
removedDisposal(); | ||
removedDisposal = undefined; | ||
} | ||
if (attributeDisposal) { | ||
attributeDisposal(); | ||
attributeDisposal = undefined; | ||
} | ||
}; | ||
if(attrData.nodeList) { | ||
ViewNodeList.register([],tearItAllDown, attrData.nodeList, false); | ||
if (removedDisposal) { | ||
removedDisposal(); | ||
removedDisposal = undefined; | ||
} | ||
if (attributeDisposal) { | ||
attributeDisposal(); | ||
attributeDisposal = undefined; | ||
} | ||
}; | ||
if (attrData.nodeList) { | ||
ViewNodeList.register([], tearItAllDown, attrData.nodeList, false); | ||
} | ||
// Listen for changes | ||
teardown = dataBinding.onTeardown; | ||
// Listen for changes | ||
teardown = dataBinding.onTeardown; | ||
attributeDisposal = domMutate.onNodeAttributeChange(el, attributeListener); | ||
removedDisposal = domMutate.onNodeRemoval(el, function() { | ||
if (el.ownerDocument.contains(el) === false) { | ||
tearItAllDown(); | ||
} | ||
}); | ||
attributeDisposal = domMutate.onNodeAttributeChange(el, attributeListener); | ||
removedDisposal = domMutate.onNodeRemoval(el, function() { | ||
if (el.ownerDocument.contains(el) === false) { | ||
tearItAllDown(); | ||
} | ||
}); | ||
}, | ||
@@ -349,3 +366,3 @@ // ### bindings.behaviors.event | ||
// The attribute name is the name of the event. | ||
var attributeName = encoder.decode( data.attributeName ), | ||
var attributeName = encoder.decode(data.attributeName), | ||
// the name of the event we are binding | ||
@@ -357,5 +374,5 @@ event, | ||
// check for `on:event:value:to` type things and call data bindings | ||
if(attributeName.indexOf(toMatchStr+":") !== -1 || | ||
attributeName.indexOf(fromMatchStr+":") !== -1 || | ||
attributeName.indexOf(bindMatchStr+":") !== -1 | ||
if (attributeName.indexOf(toMatchStr + ":") !== -1 || | ||
attributeName.indexOf(fromMatchStr + ":") !== -1 || | ||
attributeName.indexOf(bindMatchStr + ":") !== -1 | ||
) { | ||
@@ -365,3 +382,3 @@ return this.data(el, data); | ||
if(startsWith.call(attributeName, onMatchStr)) { | ||
if (startsWith.call(attributeName, onMatchStr)) { | ||
event = attributeName.substr(onMatchStr.length); | ||
@@ -399,3 +416,3 @@ var viewModel = el[canSymbol.for('can.viewModel')]; | ||
var byIndex = event.indexOf(byMatchStr); | ||
if( byIndex >= 0 ) { | ||
if (byIndex >= 0) { | ||
bindingContext = byParent.get(event.substr(byIndex + byMatchStr.length)); | ||
@@ -406,3 +423,3 @@ event = event.substr(0, byIndex); | ||
} else { | ||
throw new Error("can-stache-bindings - unsupported event bindings "+attributeName); | ||
throw new Error("can-stache-bindings - unsupported event bindings " + attributeName); | ||
} | ||
@@ -412,5 +429,7 @@ | ||
// passed in the attribute and call it. | ||
var handler = function (ev) { | ||
var attrVal = el.getAttribute( encoder.encode(attributeName) ); | ||
if (!attrVal) { return; } | ||
var handler = function(ev) { | ||
var attrVal = el.getAttribute(encoder.encode(attributeName)); | ||
if (!attrVal) { | ||
return; | ||
} | ||
@@ -422,10 +441,12 @@ var viewModel = canViewModel(el); | ||
// get parsed. | ||
var expr = expression.parse(attrVal,{ | ||
var expr = expression.parse(attrVal, { | ||
lookupRule: function() { | ||
return expression.Lookup; | ||
}, methodRule: "call"}); | ||
}, | ||
methodRule: "call" | ||
}); | ||
if(!(expr instanceof expression.Call)) { | ||
throw new Error("can-stache-bindings: Event bindings must be a call expression. Make sure you have a () in "+data.attributeName+"="+JSON.stringify(attrVal)); | ||
if (!(expr instanceof expression.Call)) { | ||
throw new Error("can-stache-bindings: Event bindings must be a call expression. Make sure you have a () in " + data.attributeName + "=" + JSON.stringify(attrVal)); | ||
} | ||
@@ -444,3 +465,5 @@ | ||
var localScope = data.scope | ||
.add(specialValues, { special: true }); | ||
.add(specialValues, { | ||
special: true | ||
}); | ||
@@ -461,13 +484,29 @@ var updateFn = function() { | ||
//!steal-remove-start | ||
Object.defineProperty(updateFn, "name", { | ||
value: attributeName + '="' + attrVal + '"' | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Object.defineProperty(updateFn, "name", { | ||
value: attributeName + '="' + attrVal + '"' | ||
}); | ||
} | ||
//!steal-remove-end | ||
queues.batch.start(); | ||
queues.mutateQueue.enqueue(updateFn, null, null, { | ||
//!steal-remove-start | ||
reasonLog: [el, ev, attributeName+"="+attrVal] | ||
//!steal-remove-end | ||
}); | ||
var mutateQueueArgs = []; | ||
mutateQueueArgs = [ | ||
updateFn, | ||
null, | ||
null, | ||
{} | ||
]; | ||
//!steal-remove-start | ||
if (process.env.NODE_ENV !== 'production') { | ||
mutateQueueArgs = [ | ||
updateFn, | ||
null, | ||
null, { | ||
reasonLog: [el, ev, attributeName+"="+attrVal] | ||
} | ||
]; | ||
} | ||
//!steal-remove-end | ||
queues.mutateQueue.enqueue.apply(queues.mutateQueue, mutateQueueArgs); | ||
queues.batch.stop(); | ||
@@ -489,3 +528,3 @@ | ||
}; | ||
var removalHandler = function () { | ||
var removalHandler = function() { | ||
if (!el.ownerDocument.contains(el)) { | ||
@@ -524,14 +563,14 @@ unbindEvent(); | ||
// to avoid (toggle)="bar" which is encoded as :lp:toggle:rp:="bar" | ||
viewCallbacks.attr(/[\w\.:]+:to$/, behaviors.data); | ||
viewCallbacks.attr(/[\w\.:]+:from$/, behaviors.data); | ||
viewCallbacks.attr(/[\w\.:]+:bind$/, behaviors.data); | ||
viewCallbacks.attr(/[\w\.:]+:raw$/, behaviors.data); | ||
bindings.set(/[\w\.:]+:to$/, behaviors.data); | ||
bindings.set(/[\w\.:]+:from$/, behaviors.data); | ||
bindings.set(/[\w\.:]+:bind$/, behaviors.data); | ||
bindings.set(/[\w\.:]+:raw$/, behaviors.data); | ||
// value:to:on:input="bar" data bindings | ||
viewCallbacks.attr(/[\w\.:]+:to:on:[\w\.:]+/, behaviors.data); | ||
viewCallbacks.attr(/[\w\.:]+:from:on:[\w\.:]+/, behaviors.data); | ||
viewCallbacks.attr(/[\w\.:]+:bind:on:[\w\.:]+/, behaviors.data); | ||
bindings.set(/[\w\.:]+:to:on:[\w\.:]+/, behaviors.data); | ||
bindings.set(/[\w\.:]+:from:on:[\w\.:]+/, behaviors.data); | ||
bindings.set(/[\w\.:]+:bind:on:[\w\.:]+/, behaviors.data); | ||
// `(EVENT)` event bindings. | ||
viewCallbacks.attr(/on:[\w\.:]+/, behaviors.event); | ||
bindings.set(/on:[\w\.:]+/, behaviors.event); | ||
@@ -556,7 +595,9 @@ // ## getObservableFrom | ||
scope: function(el, scope, scopeProp, bindingData, mustBeSettable, stickyCompute) { | ||
if(!scopeProp) { | ||
if (!scopeProp) { | ||
return new SimpleObservable(); | ||
} else { | ||
if(mustBeSettable) { | ||
var parentExpression = expression.parse(scopeProp,{baseMethodType: "Call"}); | ||
if (mustBeSettable) { | ||
var parentExpression = expression.parse(scopeProp, { | ||
baseMethodType: "Call" | ||
}); | ||
return parentExpression.value(scope); | ||
@@ -592,14 +633,16 @@ } else { | ||
//!steal-remove-start | ||
var result = "ObservableFromScope<>"; | ||
var data = scope.getDataForScopeSet(cleanVMName(scopeProp, scope)); | ||
if (process.env.NODE_ENV !== 'production') { | ||
var result = "ObservableFromScope<>"; | ||
var data = scope.getDataForScopeSet(cleanVMName(scopeProp, scope)); | ||
if (data.parent && data.key) { | ||
result = "ObservableFromScope<" + | ||
canReflect.getName(data.parent) + | ||
"." + | ||
data.key + | ||
">"; | ||
if (data.parent && data.key) { | ||
result = "ObservableFromScope<" + | ||
canReflect.getName(data.parent) + | ||
"." + | ||
data.key + | ||
">"; | ||
} | ||
return result; | ||
} | ||
return result; | ||
//!steal-remove-end | ||
@@ -632,5 +675,7 @@ }, | ||
//!steal-remove-start | ||
Object.defineProperty(getViewModelProperty, "name", { | ||
value: "viewModel."+vmName | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Object.defineProperty(getViewModelProperty, "name", { | ||
value: "viewModel." + vmName | ||
}); | ||
} | ||
//!steal-remove-end | ||
@@ -641,6 +686,6 @@ | ||
function setViewModelProperty(newVal){ | ||
function setViewModelProperty(newVal) { | ||
var viewModel = bindingData.getViewModel(); | ||
if(stickyCompute) { | ||
if (stickyCompute) { | ||
// TODO: Review what this is used for. | ||
@@ -658,3 +703,3 @@ var oldValue = canReflect.getKeyValue(viewModel, setName); | ||
} else { | ||
if(isBoundToContext) { | ||
if (isBoundToContext) { | ||
canReflect.setValue(viewModel, newVal); | ||
@@ -669,5 +714,7 @@ } else { | ||
//!steal-remove-start | ||
var viewModel = bindingData.getViewModel(); | ||
if (viewModel && setName) { | ||
canReflectDeps.addMutatedBy(viewModel, setName, observation); | ||
if (process.env.NODE_ENV !== 'production') { | ||
var viewModel = bindingData.getViewModel(); | ||
if (viewModel && setName) { | ||
canReflectDeps.addMutatedBy(viewModel, setName, observation); | ||
} | ||
} | ||
@@ -695,3 +742,3 @@ //!steal-remove-end | ||
function updateParent(newVal) { | ||
if(!bindingInfo.active) { | ||
if (!bindingInfo.active) { | ||
return; | ||
@@ -703,11 +750,11 @@ } | ||
if (!hasDependencies || (canReflect.getValue(parentObservable) !== newVal) ) { | ||
if (!hasDependencies || (canReflect.getValue(parentObservable) !== newVal)) { | ||
canReflect.setValue(parentObservable, newVal); | ||
} | ||
// only sync if parent | ||
if( syncChild && hasDependencies) { | ||
if (syncChild && hasDependencies) { | ||
// If, after setting the parent, it's value is not the same as the child, | ||
// update the child with the value of the parent. | ||
// This is used by `can-value`. | ||
if(canReflect.getValue(parentObservable) !== canReflect.getValue(childObservable)) { | ||
if (canReflect.getValue(parentObservable) !== canReflect.getValue(childObservable)) { | ||
bindingsSemaphore[attrName] = (bindingsSemaphore[attrName] || 0) + 1; | ||
@@ -719,3 +766,3 @@ queues.batch.start(); | ||
--bindingsSemaphore[attrName]; | ||
},null,[],{}); | ||
}, null, [], {}); | ||
queues.batch.stop(); | ||
@@ -728,3 +775,3 @@ } | ||
// new value is. | ||
else if(canReflect.isMapLike(parentObservable)) { | ||
else if (canReflect.isMapLike(parentObservable)) { | ||
// !steal-dev-start | ||
@@ -746,17 +793,21 @@ var attrValue = el.getAttribute(attrName); | ||
//!steal-remove-start | ||
Object.defineProperty(updateParent, "name", { | ||
value: "update "+bindingInfo.parent+"."+bindingInfo.parentName+" of <"+el.nodeName.toLowerCase()+">", | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Object.defineProperty(updateParent, "name", { | ||
value: "update " + bindingInfo.parent + "." + bindingInfo.parentName + " of <" + el.nodeName.toLowerCase() + ">", | ||
}); | ||
} | ||
//!steal-remove-end | ||
if(childObservable && childObservable[getValueSymbol]) { | ||
if (childObservable && childObservable[getValueSymbol]) { | ||
canReflect.onValue(childObservable, updateParent, "domUI"); | ||
//!steal-remove-start | ||
canReflectDeps.addMutatedBy(parentObservable, childObservable); | ||
updateParent[getChangesSymbol] = function getChangesDependencyRecord() { | ||
return { | ||
valueDependencies: new Set([ parentObservable ]) | ||
if (process.env.NODE_ENV !== 'production') { | ||
canReflectDeps.addMutatedBy(parentObservable, childObservable); | ||
updateParent[getChangesSymbol] = function getChangesDependencyRecord() { | ||
return { | ||
valueDependencies: new Set([parentObservable]) | ||
}; | ||
}; | ||
}; | ||
} | ||
//!steal-remove-end | ||
@@ -771,3 +822,3 @@ } | ||
var updateChild = function updateChild(newValue) { | ||
if(!bindingInfo.active) { | ||
if (!bindingInfo.active) { | ||
return; | ||
@@ -784,3 +835,3 @@ } | ||
--bindingsSemaphore[attrName]; | ||
},null,[],{}); | ||
}, null, [], {}); | ||
queues.batch.stop(); | ||
@@ -790,16 +841,20 @@ }; | ||
//!steal-remove-start | ||
Object.defineProperty(updateChild, "name", { | ||
value: "update "+bindingInfo.child+"."+bindingInfo.childName+" of <"+el.nodeName.toLowerCase()+">", | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Object.defineProperty(updateChild, "name", { | ||
value: "update " + bindingInfo.child + "." + bindingInfo.childName + " of <" + el.nodeName.toLowerCase() + ">", | ||
}); | ||
} | ||
//!steal-remove-end | ||
if(parentObservable && parentObservable[getValueSymbol]) { | ||
if (parentObservable && parentObservable[getValueSymbol]) { | ||
canReflect.onValue(parentObservable, updateChild, "domUI"); | ||
//!steal-remove-start | ||
canReflectDeps.addMutatedBy(childObservable, parentObservable); | ||
updateChild[getChangesSymbol] = function getChangesDependencyRecord() { | ||
return { | ||
valueDependencies: new Set([ childObservable]) | ||
if (process.env.NODE_ENV !== 'production') { | ||
canReflectDeps.addMutatedBy(childObservable, parentObservable); | ||
updateChild[getChangesSymbol] = function getChangesDependencyRecord() { | ||
return { | ||
valueDependencies: new Set([childObservable]) | ||
}; | ||
}; | ||
}; | ||
} | ||
//!steal-remove-end | ||
@@ -811,3 +866,3 @@ } | ||
}; | ||
var startsWith = String.prototype.startsWith || function(text){ | ||
var startsWith = String.prototype.startsWith || function(text) { | ||
return this.indexOf(text) === 0; | ||
@@ -818,4 +873,4 @@ }; | ||
function getEventName(result) { | ||
if(result.special.on !== undefined) { | ||
return result.tokens[result.special.on+1]; | ||
if (result.special.on !== undefined) { | ||
return result.tokens[result.special.on + 1]; | ||
} | ||
@@ -851,3 +906,3 @@ } | ||
}; | ||
canReflect.each(bindingRules, function(value, key){ | ||
canReflect.each(bindingRules, function(value, key) { | ||
bindingNames.push(key); | ||
@@ -865,4 +920,4 @@ special[key] = true; | ||
}; | ||
splitByColon.forEach(function(token){ | ||
if(special[token]) { | ||
splitByColon.forEach(function(token) { | ||
if (special[token]) { | ||
result.special[token] = result.tokens.push(token) - 1; | ||
@@ -884,3 +939,3 @@ } else { | ||
} else { | ||
return favorViewModel ? viewModelBindingStr: viewModelOrAttributeBindingStr; | ||
return favorViewModel ? viewModelBindingStr : viewModelOrAttributeBindingStr; | ||
} | ||
@@ -904,3 +959,3 @@ }; | ||
var bindingInfo, | ||
attributeName = encoder.decode( node.name ), | ||
attributeName = encoder.decode(node.name), | ||
attributeValue = node.value || ""; | ||
@@ -916,4 +971,4 @@ | ||
// check if there's a match of a binding name with at least a value before it | ||
bindingNames.forEach(function(name){ | ||
if(result.special[name] !== undefined && result.special[name] > 0) { | ||
bindingNames.forEach(function(name) { | ||
if (result.special[name] !== undefined && result.special[name] > 0) { | ||
dataBindingName = name; | ||
@@ -925,3 +980,3 @@ specialIndex = result.special[name]; | ||
if(dataBindingName) { | ||
if (dataBindingName) { | ||
var childEventName = getEventName(result); | ||
@@ -933,3 +988,3 @@ var initializeValues = childEventName && dataBindingName !== "bind" ? false : true; | ||
// the child is going to be the token before the special location | ||
childName: result.tokens[specialIndex-1], | ||
childName: result.tokens[specialIndex - 1], | ||
childEvent: childEventName, | ||
@@ -940,3 +995,3 @@ bindingAttributeName: attributeName, | ||
}, bindingRules[dataBindingName]); | ||
if(attributeValue.trim().charAt(0) === "~") { | ||
if (attributeValue.trim().charAt(0) === "~") { | ||
bindingInfo.stickyParentToChild = true; | ||
@@ -976,3 +1031,3 @@ } | ||
bindingData.templateType, el.nodeName.toLowerCase(), bindingData.favorViewModel); | ||
if(!bindingInfo) { | ||
if (!bindingInfo) { | ||
return; | ||
@@ -985,3 +1040,3 @@ } | ||
bindingInfo.alreadyUpdatedChild = bindingData.alreadyUpdatedChild; | ||
if( bindingData.initializeValues) { | ||
if (bindingData.initializeValues) { | ||
bindingInfo.initializeValues = true; | ||
@@ -992,32 +1047,32 @@ } | ||
var parentObservable = getObservableFrom[bindingInfo.parent]( | ||
el, | ||
bindingData.scope, | ||
bindingInfo.parentName, | ||
bindingData, | ||
bindingInfo.parentToChild, | ||
undefined, | ||
undefined, | ||
bindingInfo | ||
), | ||
childObservable = getObservableFrom[bindingInfo.child]( | ||
el, | ||
bindingData.scope, | ||
bindingInfo.childName, | ||
bindingData, | ||
bindingInfo.childToParent, | ||
bindingInfo.stickyParentToChild && parentObservable, | ||
bindingInfo.childEvent, | ||
bindingInfo | ||
), | ||
// these are the functions bound to one compute that update the other. | ||
updateParent, | ||
updateChild; | ||
el, | ||
bindingData.scope, | ||
bindingInfo.parentName, | ||
bindingData, | ||
bindingInfo.parentToChild, | ||
undefined, | ||
undefined, | ||
bindingInfo | ||
), | ||
childObservable = getObservableFrom[bindingInfo.child]( | ||
el, | ||
bindingData.scope, | ||
bindingInfo.childName, | ||
bindingData, | ||
bindingInfo.childToParent, | ||
bindingInfo.stickyParentToChild && parentObservable, | ||
bindingInfo.childEvent, | ||
bindingInfo | ||
), | ||
// these are the functions bound to one compute that update the other. | ||
updateParent, | ||
updateChild; | ||
if(bindingData.nodeList) { | ||
if(parentObservable) { | ||
canReflect.setPriority(parentObservable, bindingData.nodeList.nesting+1); | ||
if (bindingData.nodeList) { | ||
if (parentObservable) { | ||
canReflect.setPriority(parentObservable, bindingData.nodeList.nesting + 1); | ||
} | ||
if(childObservable) { | ||
canReflect.setPriority(childObservable, bindingData.nodeList.nesting+1); | ||
if (childObservable) { | ||
canReflect.setPriority(childObservable, bindingData.nodeList.nesting + 1); | ||
} | ||
@@ -1027,3 +1082,3 @@ } | ||
// Only bind to the parent if it will update the child. | ||
if(bindingInfo.parentToChild) { | ||
if (bindingInfo.parentToChild) { | ||
updateChild = bind.parentToChild(el, parentObservable, childObservable, bindingData.semaphore, bindingInfo.bindingAttributeName, bindingInfo); | ||
@@ -1036,3 +1091,3 @@ } | ||
if(bindingInfo.childToParent) { | ||
if (bindingInfo.childToParent) { | ||
// setup listening on parent and forwarding to viewModel | ||
@@ -1043,7 +1098,7 @@ updateParent = bind.childToParent(el, parentObservable, childObservable, bindingData.semaphore, bindingInfo.bindingAttributeName, | ||
// the child needs to be bound even if | ||
else if(bindingInfo.stickyParentToChild && childObservable[onValueSymbol]) { | ||
canReflect.onValue(childObservable, noop,"mutate"); | ||
else if (bindingInfo.stickyParentToChild && childObservable[onValueSymbol]) { | ||
canReflect.onValue(childObservable, noop, "mutate"); | ||
} | ||
if(bindingInfo.initializeValues) { | ||
if (bindingInfo.initializeValues) { | ||
initializeValues(bindingInfo, childObservable, parentObservable, updateChild, updateParent); | ||
@@ -1063,9 +1118,8 @@ } | ||
// return the function to complete the binding as `onCompleteBinding`. | ||
if(bindingInfo.child === viewModelBindingStr) { | ||
if (bindingInfo.child === viewModelBindingStr) { | ||
return { | ||
value: bindingInfo.stickyParentToChild ? makeCompute(parentObservable) : | ||
canReflect.getValue(parentObservable), | ||
onCompleteBinding: completeBinding, | ||
bindingInfo: bindingInfo, | ||
onTeardown: onTeardown | ||
value: bindingInfo.stickyParentToChild ? makeCompute(parentObservable) : canReflect.getValue(parentObservable), | ||
onCompleteBinding: completeBinding, | ||
bindingInfo: bindingInfo, | ||
onTeardown: onTeardown | ||
}; | ||
@@ -1087,6 +1141,5 @@ } else { | ||
if(bindingInfo.parentToChild && !bindingInfo.childToParent) { | ||
if (bindingInfo.parentToChild && !bindingInfo.childToParent) { | ||
// updateChild | ||
} | ||
else if(!bindingInfo.parentToChild && bindingInfo.childToParent) { | ||
} else if (!bindingInfo.parentToChild && bindingInfo.childToParent) { | ||
doUpdateParent = true; | ||
@@ -1097,13 +1150,13 @@ } | ||
// If both have a value, update the child. | ||
else if(canReflect.getValue(childObservable) === undefined) { | ||
else if (canReflect.getValue(childObservable) === undefined) { | ||
// updateChild | ||
} else if(canReflect.getValue(parentObservable) === undefined) { | ||
} else if (canReflect.getValue(parentObservable) === undefined) { | ||
doUpdateParent = true; | ||
} | ||
if(doUpdateParent) { | ||
updateParent( canReflect.getValue(childObservable) ); | ||
if (doUpdateParent) { | ||
updateParent(canReflect.getValue(childObservable)); | ||
} else { | ||
if(!bindingInfo.alreadyUpdatedChild) { | ||
updateChild( canReflect.getValue(parentObservable) ); | ||
if (!bindingInfo.alreadyUpdatedChild) { | ||
updateChild(canReflect.getValue(parentObservable)); | ||
} | ||
@@ -1114,24 +1167,32 @@ } | ||
var unbindUpdate = function(observable, updater) { | ||
if(observable && observable[getValueSymbol] && typeof updater === "function") { | ||
canReflect.offValue(observable, updater,"domUI"); | ||
} | ||
}, | ||
cleanVMName = function(name, scope) { | ||
//!steal-remove-start | ||
if (name.indexOf("@") >= 0) { | ||
var filename = scope.peek('scope.filename'); | ||
var lineNumber = scope.peek('scope.lineNumber'); | ||
if (observable && observable[getValueSymbol] && typeof updater === "function") { | ||
canReflect.offValue(observable, updater, "domUI"); | ||
} | ||
}, | ||
cleanVMName = function(name, scope) { | ||
//!steal-remove-start | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (name.indexOf("@") >= 0) { | ||
var filename = scope.peek('scope.filename'); | ||
var lineNumber = scope.peek('scope.lineNumber'); | ||
dev.warn( | ||
(filename ? filename + ':' : '') + | ||
(lineNumber ? lineNumber + ': ' : '') + | ||
'functions are no longer called by default so @ is unnecessary in \'' + name + '\'.'); | ||
} | ||
//!steal-remove-end | ||
return name.replace(/@/g, ""); | ||
}; | ||
dev.warn( | ||
(filename ? filename + ':' : '') + | ||
(lineNumber ? lineNumber + ': ' : '') + | ||
'functions are no longer called by default so @ is unnecessary in \'' + name + '\'.'); | ||
} | ||
} | ||
//!steal-remove-end | ||
return name.replace(/@/g, ""); | ||
}; | ||
module.exports = { | ||
var canStacheBindings = { | ||
behaviors: behaviors, | ||
getBindingInfo: getBindingInfo | ||
getBindingInfo: getBindingInfo, | ||
bindings: bindings | ||
}; | ||
canStacheBindings[canSymbol.for("can.callbackMap")] = bindings; | ||
viewCallbacks.attrs(canStacheBindings); | ||
module.exports = canStacheBindings; |
{ | ||
"name": "can-stache-bindings", | ||
"version": "4.2.5", | ||
"version": "4.2.6", | ||
"description": "Default binding syntaxes for can-stache", | ||
@@ -50,3 +50,3 @@ "homepage": "https://canjs.com/doc/can-stache-bindings.html", | ||
"can-symbol": "^1.0.0", | ||
"can-view-callbacks": "^4.0.0", | ||
"can-view-callbacks": "^4.2.0", | ||
"can-view-live": "^4.0.5", | ||
@@ -53,0 +53,0 @@ "can-view-model": "^4.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2866
3787
172434
29
12
Updatedcan-view-callbacks@^4.2.0