Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Making a reusable, extendable table widget with marionette that supports CRUD
- I work on a mainly server-side, horribly complex, and quite large (247 kloc) rails app. Re-use of components and testability are probably our biggest concerns. I want to introduce the team to Backbone and Marionette, so this will take place during an extended lunch and learn. Probably won't TDD it due to the amount of content I want to cover
- ## steps
- first, need to make a basic editable table
- - Make a composite view (table/container), creator view (for "new" row), and item view (for "edit/show" of rows)
- - Item view overrides getTemplate to switch between edit/show modes
- - Composite takes a creator view, instanciates it, and renders it along with its own render
- next, make it generic
- - switch initialize/onRenders to constructor/render and "call super" appropriately on all views
- - make a factory for the composite view that
- - takes item view, create view, collection
- - also can take editTemplate, rowTemplate, createTemplate, and urlRoot
- - need to have one or the other for any given "thing" (meaning, either a createTemplate or a createView is nessicary for example), if it is the more "light weight" versions, then the factory builds the classes required, setting the passed in manditory attrs
- - make a jquery plugin that takes all 7 options, invokes the factory, instanciates and renders the view, appends it to selected element, and adds it to the elements .data
- ## benefits
- - Simple cases you can very easily get a ton of functionality
- - If you want to have additional functionality for a given sub-component, it is very simple to make your own view and add it
- - Nice separation of concerns
- - Easy to test
- - Easy to reuse
- - Loads of functionality for relatively little code
Add Comment
Please, Sign In to add comment