Starting with the web page, I require
main.js, I require my main
calendar.jslibrary and use the class defined in that library to instantiate a new calendar application:
define()function lists the library dependencies, passing them to an anonymous callback function. In this case, I need jQuery, Underscore.js, and Backbone:
All of that works just fine. What I would like to get started on today is extracting individual model, collection, and view classes out into individual files to be
require'd via require.js.
In the absence of definitively knowing the best way to begin, I start at the top. That is, I remove the
Appointmentmodel class from
With that, I need to make two changes back to my monolithic
Models.Appointmentinternally. Fortunately, this requires just two changes:
Something to note here is that I am only using my model in once place—the collection. If I extract my collection out into a require.js library, then the collection library can depend on the model and my application can depend on the collection. The application need never know about the model.
So, I extract my collection out into it own library:
Back in my no-longer-quite-monolithic
calendar.js, I replace the dependency on the
Appointmentmodel with a dependency on the
Appointmentsclass. I then replace the collection instantiation with the new class name:
calendar.jsapplication class—it will always be the application's job to instantiate the list of appointments to be populated on my calendar.
With two classes extracted out into require.js libraries, I call it a night. Up tomorrow: Views.