Mac mast structure

I have an application built on Backbone. As it becomes more complex, I appreciate the transition to Marionette, but I'm not sure how to structure my views.

Existing application views are structured as follows:

BaseView = Backbone.View.extend({ ... }) 

BaseView is the root of all views. It basically has a rendering function with basic elements, such as: rendering templates, page localization, selecting the active menu, etc.

 ListView = BaseView.extend({ ... }) 

Here, the rendering method contains common code for all lists, such as loading and using the DataTables plugin, common events for edititem, additem, deleteitem, etc.

 FormView = BaseView.extend({ ... }) 

It manages generic forms using the Backbone.ModelBinder plugin and handles form validation.

All of my app views range from one of the above to improve code reuse. For example, I have an AccountFormView that extends from FormView, where I only have certain logic (a few lines of code) to process account information. All common logic is inherited from the ideas of parents.

How can I get something like this using Marionette Views?

Thanks Fabrizio

+4
source share
1 answer

Puppet views are configured to handle the most common situations and remove all template code from these common problems:

  • View: A basic view that can be used to create other views.
  • ItemView: display one model with a template
  • CollectionView: visualize each model in the collection using the specified itemView
  • CompositeView: Render the template as a wrapper around the collection view. supported nested / hierarchical structures.

In your situation, it sounds like you will be using a combination of these types of viewing, depending on the specific scenario in which you are located. Instead of always having one type of view, one that makes the most sense for the current scenario and extends from it.

If you are looking for a way to add your own custom functions to all views, it is also very simple - just add this function to the Marionette.View or Backbone.View database and it will be available for all kinds of puppets.

Be sure to check the documentation and the code (it is divided into many small files, so it’s easy to read and understand) to find out what methods Marionete provides you and what extension points it also provides.

Hope this helps.

+4
source

Source: https://habr.com/ru/post/1441940/


All Articles