In Aurelia it is really difficult to react to dynamic changes to the markup that result from if and repeat.for binding updates. I was testing a custom attribute that extended the attached method on the view to enable this and I noticed that the logic for animateView
is set up to be the perfect hook for my purposes.
After the ViewSlot is attached/detached it calls the animateView
method which looks for an animatableElement and if it finds one it passes it into this bit of logic:
switch (direction) {
case 'enter':
return this.animator.enter(animatableElement);
case 'leave':
return this.animator.leave(animatableElement);
default:
throw new Error('Invalid animation direction: ' + direction);
}
Instead on looking for animatableElement (typically an element denoted with a āau-animateā class) and calling the this.animator.enter
or this.animator.leave
functions we could instead use a binding:
The binding could be something like this:
<div if.bind="showElement"
animate-view="
enter.bind: onElementEnter($element);
leave.bind: onElementLeave($element)">
</div>
or something like this:
<ul class="accordion">
<li repeat.for="item of list"
animate-view.bind="onAnimate($element, $direction)"
class="collapsible ${$direction=== 'enter' && item.expanded ? 'expand' : 'collapse'}">
</li>
</ul>
The element with the binding would be the āanimatableElementā and the binding expressions would replace the default this.animator.enter
and this.animator.leave
methods. I think this would make it much easier to interact with dynamic content. Would a change like this be possible without creating a performance problem or breaking other aspects of the framework?