BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

Strange behaviour with ~variable && ~variable^length > 0, where ~variable = ~getVariable() #388

Closed artemipanchuk closed 7 years ago

artemipanchuk commented 7 years ago

Please, take a look at following fiddle: https://jsfiddle.net/nq4372t8/26/

There, as you can see, are 4 different "ways" to describe logic of checking some value.

First two ways do ~t=item, and second two ways do ~t=getItem(). 1-st and 3-rd ways are checking result in variable with one if tag, as {^{if ~t && ~t^length>0}} .... 2-nd and 4-th ways are checking result in variable with two if tags, as {^{if ~t}} {^{if ~t^length>0}} ....

The question is: why does jsrender conider result of {^{if ~t && ~t^length>0}} as false in 3-rd example? We think, it is similar to other examples. Is it correct? If it is, then what point do we miss?

Thanks.

BorisMoore commented 7 years ago

Yes, good catch, thank you. It is a bug. I am working on a fix. I'll let you know...

BorisMoore commented 7 years ago

Here is a patched version. Let me know whether it works correctly for you... Thanks... jsviews.js.txt

gbouthenot commented 7 years ago

Seems like an operator precedence problem. If you do {^{if (~t) && (~t^length>0)}}, it works.

artemipanchuk commented 7 years ago

Thanks for your quick response. Looking forward to see new release with these fixes.

BorisMoore commented 7 years ago

@gbouthenot: It is actually a bug. The array returned by ~t was not getting data-linked for array changes, so the ~t^length was not updating from 0 to 1 when an item was inserted into the array.

@artemipanchuk: The fix (jsviews.js.txt) did work for your environment, right?

artemipanchuk commented 7 years ago

@BorisMoore sure, your fix worked in my case too. This issue can be closed after new release.

BorisMoore commented 7 years ago

Good. I'll include it in the next update...

BorisMoore commented 7 years ago

Resolved in commit 88