A
Behavior
is an isolated set of DOM / user interactions that can be mixed into anyView
or anotherBehavior
.
Behaviors allow you to blackbox
View
-specific interactions into portable logical chunks, keeping your Views simple and your code DRY.
Explications, implémentation et détails techniques très bien présentés par Stéphane Bachelier au meetup Backbone.js Paris S01E06
const Alert = Marionette.Behavior.extend( {
defaults: {
title: "Alert!",
message: "Not really urgent"
},
events: {
"click": "emitAlert"
},
emitAlert() {
alert( this.options.message );
}
} );
it( "should emit an alert", () => {
// => This won't work
expect( Behavior.emitAlert() ).toEmitAnAlert();
} );
Tester une Behavior indépendamment d'une vue :
Tester l'interaction Behavior-View dans chaque test de vue…