Releases: PhpGt/DomTemplate
Count bound list items
A very small release here, changing the void
return type from bindList
to int
, so you are informed of how many items were bound to the DOM.
Boolean attribute binding
For attributes that don't have a value, like disabled
, selected
, checked
, etc. a new bind rule is added in this release, meaning the attribute will be added if a boolean condition is met.
The attribute value is marked with a preceding question mark. For example: <input type="checkbox" data-bind:checked="?isChecked" />
Small but powerful when working with large repeating datasets.
Have fun and stay productive!
Efficiency improvement
This release changes the internal mechanism for binding lists to the DOM. Rather than appending Elements to the DOM tree in-place, a list is built up in a separate DocumentFragment, and once complete, the fragment is appended to the ParentNode, greatly improving page render speeds on complex documents with many nodes.
Another efficiency improvement is the addition of data-bind
parameter` attribute, which now must be added to any Element that will have its parameters bound inline, using curly braces. This is a small backwards breaking change, hence the minor version increment, as before any parameters containing curly braces would be automatically bound.
Update DOM dependency
This release introduces the fixes made to the Dom repository upstream.
DataBindMapper and DataBindGetter interfaces
The introduction of the two new interfaces DataBindMapper and DataBindGetter allow the developer to state that a class can be used in the DomTemplate bind functions, without having to expose the data as public properties.
DataBindMapper defines a function, dataBindMap
which must return an associative array, and will be called in the bind process.
DataBindGetter does not define any functions, but instead indicates to DomTemplate that the class should have its get* functions called for any keys that are bound. For example, binding a key of id
will try to call the getId
function on the class.
Less strict types
With a small bump of dependencies, this release contains only one minor change: the ability to pass bound keys and values as null. When a null value is bound, it is treated as an empty string.
Usability improvements
Typehints have been made less strict in some areas, so objects or associative arrays can be used as the data.
The bind
function has been introduced as an alias to the bindKeyValue
function.
In the binding of list items, the data is bound to the nodes after they are inserted into the DOM to avoid incorrect referencing issues after complete.
Stable release (with bindable DOM)
Before a stable release could be made, the way that data was bound to the DOM needed to be addressed. Currently (v0.6.x) this was too complex, because no matter what type of data you had, everything was bound to the DOM through the Element::bind()
function. That included key value pair storage, lists, and if there was data that needed to be bound to a nested list it was impossible to bind without iterating over it yourself.
The stable release introduce introduces, amongst a generous amount of bugfixes and test hardening, the addition of the following new functions:
- bindKeyValue
- bindData
- bindList
- bindNestedList
They should be self-explanatory now, and depending on the data that you wish to bind to the page, should be very obvious as to which function you should be calling.
Have fun, and stay productive!
DocBlocks
Throughout the repository, all classes have received PHP Doc Block comments to describe to IDEs what types are being returned by inherited functions. This is required because of the use of DOMDocument::registerNodeClass
, which has some unusual side effects with the way classes are inherited in the DOM.
Improvements to tests
PHPUnit 8 has been introduced and tests adjusted accordingly. Continuous Integration services are now updated to work with the latest version of PHP.