walmartlabs/thorax

Behaviors a la Marionette

Closed this issue · 2 comments

Lately, Marionette as introduce the concept of Behaviors, a piece of logic attached to a view.

This idea allows to have a proper separation of concern without the use of inheritance.
Something like this:

var ToolTip = Thorax.Behavior.extend({
  events: {
    ready: 'attachTooltip'
  },

  attachTooltip: function() {
    this.$('.tooltip).tooltip({ text: this.options.text });
  }
});

var view = Thorax.View.extend({
  behaviors: {
    ToolTip: { text: "what a nice mouse you have" }
  }
});

Any plan to add something similar to Thorax (or maybe there is already something similar)?

Mixins would be our equivalent as best I can tell. Are there specific behaviors that are missing?

By mixins you mean template helpers, right?

If this is right, you cannot predict all the specific behavior.
For example, activate a jquery plugin after 'on ready', or gather a piece of logic (like clicking on specific button to reveal an help). This has to be made in the JS files, and this favor composition over inheritance.

Is my first example not clear enough?
Thanks.