-
Notifications
You must be signed in to change notification settings - Fork 17
Implement sort and filter array filters #13
Comments
Talked about this today with @esprehn. For filtering, we came up with a strawman syntax: <template repeat="{{ foo in foos where foo.barCount > 0 }}">
...
</template> From my (naive) understanding of polymer-expressions, this looks pretty "simple": generated binding observs both |
This would save on us having to keep implementing custom |
@addyosmani I think that's an excellent question, but it may be separate from the issue of providing filtering/sorting in template repeat. As I noted above, the thing on the right of "where" is just an expression. For example, suppose each <template repeat="{{ foo in foos where foo.bars[$].bazCount > 0 }}"> The <template if="{{ foo.bars[$].bazCount > 0 }}"> I don't see a need to tie these two capabilities, though I agree that they would be useful together. In fact, #31 hints at some of the same issues (needing to express a broader set of dependencies than a path from an object). |
Originally the notion was to try to emphasize JavaScript over declarative syntax for a couple of reasons. One issue is that JS filter functions go directly on the prototype and then are shared. This kind of construction has to be parsed and interpreted per-instance. Is this a real concern? Another is that the view template can become spammed with data logic that is more properly expressed in the model or the presenter. But I suppose this is mostly a slippery-slope argument, and is much less convincing. |
The problem with doing this imperatively is that you then need to build the "kick" system to keep telling the template binding framework which I'd expect to be able to use this in a computed property so the template isn't crazy. computed: {
filteredFoos: "foo in foos where foo.bars[$].bazCount > 0"
} and later <template repeat="{{ foo in filteredFoos }}"> |
Re-parsing again seems like a separate issue. I don't see any reason why we should be re-parsing bindings expressions per-instance; if we are, it sounds like a nice optimization to be made. I definitely see the "too much logic in the template" argument, and it's why I wanted to think of the extended expression syntax for object/array observation as an extra addition. My first comment suggested that for starters, we could simply support any existing expression on the RHS of |
Thanks for the thoughts guys. If we can put the expressions in the |
seems like a good idea. I see the "where" syntax proposal, would it also include some kind of "sort by" as syntax? But here is an example: <template repeat="{{ foo in foos order by foo.score }}">
...
</template> |
Another idea would be to reverse precedence between repeat and if, such that: <template repeat="{{ foo in foos where foo.barCount > 0 }}"> could be written as: <template repeat="{{ foo in foos }}" if="{{ foo.barCount > 0 }}"> that's a backwards from the current precedence, though. Yet another thought is: <template repeat="{{ foo in foos }}" where="{{ foo.barCount > 0 }}"> One good point in Polymer/old-docs-site#583 -- due to the need for template attribute on IE such as edit: formatting |
Moved from: googlearchive/TemplateBinding#103
The text was updated successfully, but these errors were encountered: