Example
Two elements bound to two different colours. The handler swaps their binding attributes and asks Bindary to
re-read both, which it can only do because the attributes are still there.
<div b-context="demo.keep">
<label>
<input type="checkbox" b-on-change="$bindary.controller.swapColors" /> swap colors?
</label>
<div id="colorA" class="demo-swatch" b-keep="true" b-value="color1"
b-attributes="style = color: {{color1}};"></div>
<div id="colorB" class="demo-swatch" b-keep="true" b-value="color2"
b-attributes="style = color: {{color2}};"></div>
</div>
$bindary.appData.demo.keep = { color1: "Red", color2: "Orange" };
ctrl.swapColors = () =>
{
let valueAttr = 'b-value',
attrAttr = 'b-attributes',
a = $('#colorA'), b = $('#colorB'),
value = a.getAttribute(valueAttr),
attr = a.getAttribute(attrAttr);
a.setAttribute(valueAttr, b.getAttribute(valueAttr));
a.setAttribute(attrAttr, b.getAttribute(attrAttr));
b.setAttribute(valueAttr, value);
b.setAttribute(attrAttr, attr);
[a, b].forEach($bindary.updateTemplateItem);
$bindary.updateView(true);
};
Result
This is the third case above: what changes is not the data but which key each element points at. Swapping
attributes and re-reading them is only possible because they are still on the element.