Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler definition for types of binding operations #110

Closed
g105b opened this issue Nov 18, 2019 · 0 comments
Closed

Simpler definition for types of binding operations #110

g105b opened this issue Nov 18, 2019 · 0 comments
Assignees
Milestone

Comments

@g105b
Copy link
Member

g105b commented Nov 18, 2019

For the purposes of the description here, the term BindableValue will act as a union type of either:

  • a primitive, like a string, int or float.
  • an object with a __toString function.

The term BindableData will act as a union type of either:

  • an associative array of key-values, where the values are of type BindableValue.
  • an object with public properties, acting as key-values.
  • an object that implements the BindDataGetter or BindDataMapper interfaces.

The bind function will make a call to the following bind functions, depending on the parameters passed into it:

  • bindValue(BindableValue $value) - binds any element(s) in the tree that has a data-bind:X attribute without a key name.
  • bindKeyValue(string $key, BindableValue $value) - binds any element(s) in the tree that has a data-bind:X=Y attribute, where Y matches $key.
  • bindData(BindableData $data) - calls bindKeyValue for every key-value-pair of $data.
  • bindList(iterable $list) - creates a template element for each iteration, and calls bindData on the template element, passing the value of the iterator. This functionality is broken down below.
Breaking down bindList

The iterable $list is bindList's only parameter, but its contents can determine the function's behaviour (sometimes recursive).

For every iteration of the iterable, a new template element is cloned. The first extracted template element that matches the current context element's nodePath is used as the template element.

Once a template element has been cloned, bind functions will be applied to it. If the $list is an associative array (or anything other than an indexed array/iterator), the key is passed to bindValue on the current template element.

If the value is a BindableValue, the value is passed to bindValue. Therefore, an associative array of strings would not be a valid $list, and an exception must be thrown.

If the value is a BindableData, the value is passed to bindData.

If the value is iterable, the value is passed to bindList again (recursively), but the context node shifts to the newly cloned template.

@g105b g105b self-assigned this Nov 18, 2019
@g105b g105b added this to the v2 milestone Nov 18, 2019
g105b added a commit that referenced this issue Nov 26, 2019
@g105b g105b closed this as completed in 7468beb Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant