Closed cherifGsoul closed 5 years ago
The docs don’t mention being able to use !
. I think this would be a nice feature.
This should be fixed in can-stache/src/expression.js
In can-stache
add !
to tokens pattern:
https://github.com/canjs/can-stache/blob/83191d3c312845acc70f103d167ef378625284ca/src/expression.js#L37
->
var tokensRegExp = /('.*?'|".*?"|=|[\w\.\\\-_@\/*%!\$]+|[\(\)]|,|\~|\[|\]\s*|\s*(?=\[))/g
Update Lookup
:
https://github.com/canjs/can-stache/blob/83191d3c312845acc70f103d167ef378625284ca/expressions/lookup.js#L11 ->
var Lookup = function(key, root, sourceText) {
this.inverse = false
// Read falsy value of the key starts with "!"
if (key.substring(1, key.length)) {
this.key = key.slice(1);
this.inverse = true;
} else {
this.key = key;
}
this.rootExpr = root;
canReflect.setKeyValue(this, sourceTextSymbol, sourceText);
};
in can-stache-bindings
:
https://github.com/canjs/can-stache-bindings/blob/master/can-stache-bindings.js#L549 ->
var hashExprs = expr.hashExprs;
var key = Object.keys(hashExprs)[0];
var isInverse = hashExprs[key].inverse;
var value = expr.hashExprs[key].value(runScope);
var isObservableValue = canReflect.isObservableLike(value) && canReflect.isValueLike(value);
var valueToBind;
isObservableValue ? valueToBind = canReflect.getValue(value) : valueToBind = value;
runScope.set(key, isInverse ? !valueToBind : valueToBind);
The following does not work:
<button on:click="this.isOpen = !this.open"> Toggle </button>
Seems is only working with primitive values, setting the value
this.isOpen
totrue
orfalse
works fine.A CodePen https://codepen.io/cherifGsoul/pen/KYMdma for issue demonstration.