knockout-fast-foreach
knockout-fast-foreach copied to clipboard
Maybe templating shouldn't be supported
Because fastForEach
doesn't use the native template
binding internally for rendering templates, it can lead to several issues like
- Won't get any fixes related to
template
binding. - Can't use any feature of
template
binding, like engines, etc. - If one overrides/customizes the
template
binding, he might expect that thefastForEach
template syntax will make use of it, but counter-intuitively it won't
I suggest removing the templating options and syntaxes, and recommending using an inner template
binding like this.
<div data-bind='fastForEach: items">
<!-- ko template: 'my-name' -->
<!-- /ko -->
</div>
Or the same with non-containerless version if one can allow it.
This is be a breaking change of course, and should be added only into the final version IMO.
Yeah, I think for TKO-alpha/beta this would be wise.
I don't know the native template
's foreach
option's implementation very well, but you should take that into account too, because that may interfere with fastForEach
as well.
I actually just got around to testing this today, and this is literally the only way I use foreach. My entire site is a bunch of these
<!-- ko with: blog -->
<div data-bind="template: { name: 'pagination' }"></div>
<div data-bind="template: { name: 'post', foreach: posts, as: 'post' }"></div>
<div data-bind="template: { name: 'pagination' }"></div>
<!-- /ko -->
Except the ones that are components of course. So as of today, this doesn't seem to work for me. I would prefer this syntax stick around personally, I find it graceful, useful, and extremely easy to come back to after months of not seeing the code.
If I had to switch to the template inside a foreach syntax, it wouldn't be the end of the world, but I'd prefer not to for sure.
@jlaustill I ment the fastForEach
binding syntax which let's you pass a template name. I didn't mean to touch the template
syntax with the foreach
options, that's a different story.
However, if fastForEach
gets into the knockout core and possibly replaces the original foreach
, the template
syntax you mentioned should be something to think about. But I think we could at least call fastForEach
and template
respectively under the hood, so that the syntax would remain the same.