Questo può essere fatto con Aurelia custom attributes funzione.
Creare un nuovo file javascript per descrivere l'attributo (ho chiamato l'attributo "animateonchange"):
import {inject, customAttribute} from 'aurelia-framework';
import {CssAnimator} from 'aurelia-animator-css';
@customAttribute('animateonchange')
@inject(Element, CssAnimator)
export class AnimateOnChangeCustomAttribute {
constructor(element, animator) {
this.element = element;
this.animator = animator;
this.initialValueSet = false;
}
valueChanged(newValue){
if (this.initialValueSet) {
this.animator.addClass(this.element, 'background-animation').then(() => {
this.animator.removeClass(this.element, 'background-animation');
});
}
this.initialValueSet = true;
}
}
Riceve l'elemento e CSS animatore nel costruttore. Quando il valore cambia, anima l'elemento con un nome di classe CSS predefinito. La prima modifica viene ignorata (non è necessario animare al caricamento iniziale). Ecco come utilizzare questo elemento personalizzato:
<template>
<require from="./animateonchange"></require>
<div animateonchange.bind="someProperty">${someProperty}</div>
</template>
Vedi l'esempio completo in my blog o on plunkr
Come fa i dati vengono modificati? Cosa cambia? – dfsq
@dfsq Visualizza il modello da websocket e aggiorna un elemento nel campo "items". Il binding di Aurelia aggiorna quindi il DOM. – Mikhail
È necessario utilizzare il modulo aurelia-animator-css. Creerò un esempio più tardi se non lo capisci da solo. – dfsq