While at JS.GEO, I talked with a number of people who were interested in using Backbone & Marionette in a mapping application, but only a few had dabbled with it to any extent. So I thought it would be useful to create a short series where I walk through building a simple, configuration based, single-page mapping app using Backbone Marionette.
Enter Marionette – created by Derick Bailey – it is a composite application library, which add’s more “opinions” into the mix. It provides number of implementations of common design patterns, which helps to keep the code cleanly separated, while still having consistent structure so applications follow predictable patterns.
With Marionette, we still have the Backbone Models, Collections and Views, but we get some other very handy things – like Composite views ( automatic handling of parent-child relationships), formalized Controllers, Modules and an over arching Application. Additionally Layouts and Regions streamline the re-use of areas of the UI, and ensure event handlers are correctly released so we avoid zombies and memory leaks.
About the App
What I wanted to explore, in addition to the “configuration by default” idea, was a means to cleanly separate the various parts of the app, following the single responsibility principle. We will do this more or less the same way we would do this in a desktop application – by leveraging events and keeping the various components ignorant of each other.
For example – this will allow us to have a (minimal) “layer list” view, that is responsible for allowing the user to show/hide layers in the map, but it will not have any direct references to the map. This clean separation will mean that all our “map” code will be contained in one place (a module).
Finally, assuming I pull this all off semi-sanely, the last part of the project will be to swap out the Esri Map Module for an implementation based on Leaflet, without changing a single line of code in any other components! This should be interesting to see how many of the “Esri-isms” leak up through this abstraction layer, and complicate things in a non-Esri map.
Anyhow – I’ll be learning a heck of a lot as we go through this, so input is certainly welcome.