0

Im pretty new to Marionette.js / Backbone.js but I have a lot of experience with Angular and most recently React.

I have a Marionette app and in that app we have a special form control that creates tags and makes suggestion, something like this http://sliptree.github.io/bootstrap-tokenfield/

I have this exact same control in various parts of the app and hence the problem and the question being asked:

How can I abstract that component and re use it across the app? it has a markup template, with some minimal template logic, it uses some templateHelpers and the jquery plugin that supports it needs to be instantiated onShow.

In a React.js app I will do something pretty simple as this:

<form>
  ...
  <mySpecialControl {...someProps}/>
</form>

And in the def of mySpecialControl I will encapsulate all the logic.

Is there any way of accomplishing something analogous in a Marionette / Backbone app?

franleplant
  • 629
  • 1
  • 7
  • 17
  • 1
    Have you had a look at [Behavior](http://marionettejs.com/docs/v2.4.4/marionette.behavior.html)? – ivarni Dec 01 '15 at 06:14
  • You can use reactjsx with Backbone/Marionette – Sergey Dec 01 '15 at 13:03
  • Behaviors are good but markup still needs to be duplicated. I know I can use React but that's a whole business/managing/architecture discussion in neither of which I am involved – franleplant Dec 01 '15 at 13:53

1 Answers1

0

The short answer is that Marionette does not prescribe a certain approach for doing this.

You can easily just create a marionette view for the component that you want throughout your app and then instantiate it when you need it. My assumption is that you might already have a view for this component and you just need to put its definition somewhere more general with an easy way to access it from anywhere.

Without a more specific scenario it is hard to give more specific advice.

Siyual
  • 16,415
  • 8
  • 44
  • 58
dchapman
  • 365
  • 5
  • 20
  • The problem with views is that they are still cumbersome. I need to create the view + template. But from the user of that view perspective, she will need to define a dom element where the view will be instantiated, instantiate the view, and probably manage it's destroy cycles. Thanks a lot for your answer. – franleplant Dec 04 '15 at 14:26