Lit-html: Update guard() to support multiple values.

Created on 21 Nov 2018  路  3Comments  路  Source: Polymer/lit-html

The guard name has been confusing for users. memo seems to be common enough with it's addition to React, that it should be a bit better.

We also want to support multiple checked values.

High Enhancement

Most helpful comment

We decided to keep the name guard().

memo() isn't _that_ familiar as you point out, and it's not quite right because we're not directly memoizing the function.

All 3 comments

Not being a react user I don't know what memo means, whereas guard I understand in the sense I know what it does - not necessarily how to use it properly (see below). I certainly view it as a sort of guarded border which prevents irrelevant changes passing through to something that is large and complex and should only be re-evaluated when necessary.

Yesterday I spent a few hours chasing down why my model had one view of the data and the display had another. It was guard that was preventing a pass down of property data to an embedded element (which would have caused it to-re-render) despite (I though) being meticulous on ensuring my object reference changed when data within it had changed. I never understood why I wasn't piercing the guard so I just I took my guard out and rendering worked and performance didn't seem to change. I guess I could be guilty of too early an optimisation, but the experience has made be question the value of the directive and exactly when it should be used. So some really good documentation would be useful.

I like the multiple values. I ended up in one scenario just adding a field to my object which was always a {} (but was easy to change to another {} when I wanted to pierce the guard because I really wanted to pierce the guard if one of several fields changed.

Your understanding of the directive is why I originally chose the name "guard". We've heard other feedback that the name is confusing. Especially in the context of the "until" and "when" directives. Together they're just vague enough to be confusing. Maybe this is better since we removed "when", are adding "cache" instead and renaming "until" to "async". The domain of the new directives is much clearer now.

We decided to keep the name guard().

memo() isn't _that_ familiar as you point out, and it's not quite right because we're not directly memoizing the function.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakom picture dakom  路  4Comments

MVSICA-FICTA picture MVSICA-FICTA  路  5Comments

Christian24 picture Christian24  路  4Comments

cbelden picture cbelden  路  4Comments

dflorey picture dflorey  路  4Comments