Skip to content

ForEachBinding does not match the documented callback API of foreach #329

@dvHuett

Description

@dvHuett

In build.reference, the foreach Binding behavior comes from ForEachBinding. However, the foreach Binding documentation describes the callback behavior provided by TemplateForEachBindingHandler used in build.knockout, resulting the documented API and the actual runtime behavior in the reference build to not fully match.

Problematic behavior

ForEachBinding is only partially compatible with the callback API described for the foreach Binding:

  • afterRender is not supported by ForEachBinding
  • beforeMove is not supported by ForEachBinding
  • afterMove is not supported by ForEachBinding
  • afterAdd exists in ForEachBinding, but uses a different callback contract than TemplateForEachBindingHandler
  • beforeRemove exists in ForEachBinding, but also uses a different callback contract than TemplateForEachBindingHandler

Expected behavior

The behavior of foreach in build.reference should be aligned with one of these expectations:

  • ForEachBinding should support the same documented callback API as TemplateForEachBindingHandler, or
  • the foreach Binding documentation should clearly distinguish between the callback behavior of ForEachBinding and TemplateForEachBindingHandler

Why this is a problem

This creates a silent compatibility gap between the documented foreach API and the actual behavior of ForEachBinding in the reference build. Rendering may still work, but lifecycle hooks such as afterRender do not run, and callbacks such as afterAdd and beforeRemove are invoked with a different signature than the one described in the documentation.

Suggested clarification

Please clarify whether the different callback behavior of ForEachBinding is intentional. If it is intentional, the documentation should explicitly document the differences from TemplateForEachBindingHandler. If it is not intentional, ForEachBinding should be brought closer to the documented foreach callback behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions