jmurphyau/ember-truth-helpers

Lazy evaluation

Techn1x opened this issue · 5 comments

So if I use the and helper like so;

{{if (and firstExpression secondExpression)}}

It will evaluate both firstExpression and secondExpression even if firstExpression is false.

Is there a way to get it to evaluate just the firstExpression and stop there when it fails? The reason I ask is because 99% of the time my secondExpression is not necessary, and is quite taxing, so I only want to evaluate it when necessary.

I am trying to do this with ember-truth-helpers because both of my expressions are actually handlebar helpers :p

Sadly, no. This is a limitation of glimmer-vm’s helper implementation at the moment. Definitely something that would be nice to fix, it as with most things “it’s complicated”.

Thanks for the response :) guess I'll have to see if I can re-write some of my helpers into a computed property

Sorry. Closing for now.

I guess in theory this would be an alternative approach to achieve lazy evaluation;

{{#if firstExpression}}
  {{#if secondExpression}}
    {{doSomething}}
  {{/if}}
{{/if}}

Sure, but definitely is annoying :D