knockout-fast-foreach icon indicating copy to clipboard operation
knockout-fast-foreach copied to clipboard

Maybe templating shouldn't be supported

Open cervengoc opened this issue 8 years ago • 4 comments

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 the fastForEach 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.

cervengoc avatar Oct 13 '16 10:10 cervengoc

Yeah, I think for TKO-alpha/beta this would be wise.

brianmhunt avatar Oct 13 '16 13:10 brianmhunt

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.

cervengoc avatar Oct 13 '16 13:10 cervengoc

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 avatar Dec 13 '16 19:12 jlaustill

@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.

cervengoc avatar Dec 13 '16 20:12 cervengoc