Structuring Backbone Code with RequireJS and Marionette Modules
Structuring Backbone Code with RequireJS and Marionette Modules
Learn to use javascript AMD in your apps the easy way
About the Book
The book is up to date for Marionette 2.3. In addition, you also receive the book covering Marionette 1.7.4.
Due to popular demand from my well-received previous book on Marionette (Backbone.Marionette.js: A Gentle Introduction), I've taken the Contact Manager application developed in that book and rebuilt it using RequireJS to load dependencies. It has great feedback so far, and I hope you'll like it, too!
Who This Book is For
Essentially, this book is written as a sequel of sorts to my first book. If you want to learn about using RequireJS and AMD (Asynchronous Module Definition) to use in your own applications, you should be fine following along provided you're comfortable with Marionette and its modules, as well as the Contact Manager application (see its source code). In other words, this book does not cover how to develop a Marionette application, only how to use RequireJS to manage dependencies and optimization/minification. If you want to learn how to create a Marionette application, refer to my Backbone.Marionette.js: A Gentle Introduction book.
What You'll Learn
Rebuilding the existing Contact Manager application, but using RequireJS to load all dependencies (other modules, libraries, templates, etc.). Common errors and their likely cause will be discussed, so you can debug your own projects more easily. Running the r.js optimizer to generate a single, minified js file will be demonstrated. In addition, you will actually understand and learn how to "think AMD" and how to apply that mindset to your own projects.
Starting/stopping sub-applications to improve performance will be demonstrated, as well as loading libraries from a CDN, with a local fallback.
Although this book is focused on using RequireJS with Backbone and Marionette, once you're done with it you should be able to use RequireJS in other projects. This is because the book emphasizes the logic behind the implementation, and once you've understood how to use shims and load dependencies, applying this knowledge to your own projects should be straightforward.
How This Book is Structured
This book's goal is to make you independent and productive using RequireJS. As such, only the first chapter is written as a step-by-step guide. Subsequent chapters will be structured as exercises (with step-by-step solutions): each chapter will introduce the objective (e.g. implementing a new module), will point out various things to keep in mind (required libraries, dependencies, etc.), and will explain new concepts you'll need to use in the chapter.
After that, you're on your own: you will implement the new module by yourself. Of course, if at any time you get stuck, you can continue reading the chapter and you will see the step-by-step implementation explaining how the new module is implemented.
What Readers Are Saying
I've included some sample reader feedback below, but if you need more convincing take a look at the feedback page.
This book builds nicely on David's "Gentle Introduction". In my case I had used RequireJS and then needed to retrofit Marionette modules to my code, so the flow described in the book itself wasn't directly useful to me, however seeing how David had married the two was very useful. The initial material on best practice require.js configuration and the broader discussion on Marionette modules versus Require JS modules were also good. As I continue to work on my code I find myself flicking back through the book regularly to see how he has approached similar problems. -- Christo Fogelberg
I have read both of Sulc's books 3 times. I've spent the last 3 years in Objective-c land, so diving back in to JS has required a little brush up. He has provided me with a fantastic foundation. If you have wandered down the JS rabbit hole and found Marionette and company you are definitely in the deep end. But come on in the water is fine. I haven't had this much fun writing code in my life. Well done David! -- Chet Harrison
Structuring Backbone Code with RequireJS and Marionette Modules was a natural progression after reading David's first book on Marionette and very worthwhile. Being already comfortable with RequireJS I was more interested in how Marionette modules were tied in and these were explained really well. He explains the concepts clearly and makes weaving these two libraries together quite easy. -- Mark Coleman
This is another great book of yours that helped me a lot to get my head around Backbone + Marionette + RequireJS. And it came at a vary good time - just when I got into trouble while adding RequireJS to my Marionette project. -- Mickey Vashchinsky
Bundles that include this book
Table of Contents
- Who This Book is For
-
Following Along with Git
- Jumping in for Advanced Readers
- Why Use AMD?
-
Getting Started
- Adding RequireJS to the Mix
- Using Shims
-
Loading the Main App
- Discovering Modules
- Turning ContactManager into a RequireJS Module
-
Listing Contacts
- Modularizing the Contact Entity
- Using the Contact Entity from the Main App
- Listing Contacts from the List Sub-Application
- Requiring Views and Templates
-
Editing Contacts with a Modal
- Including the jQuery UI Dialog Dependency
- Expliciting Dependencies
-
Creating Contacts with a Modal
- Exercise Solution
- Further Decoupling of the Contact Module
-
Filtering Contacts
- Exercise Solution
-
Adding the Loading View
- Exercise Solution
-
Showing Contacts
- Exercise Solution
-
Editing Contacts
- Exercise Solution
-
Reimplementing the About Sub-Application
- Exercise Solution
-
Reimplementing the Header Sub-Application
- Exercise Solution
-
Marionette Modules VS Plain RequireJS Modules
- Converting the Contact Entity to Plain RequireJS Modules
- Using a Separate Module as the Event Aggregator
- Converting the Collection
- Rewriting the Show View
- Rewriting the Show Action
-
Start/Stop Modules According to Routes
- Implementation Strategy
- Modifying the AboutApp
-
Mixing and Matching Modules
- Converting the About Sub-Application to Plain RequireJS Modules
- Managing Start/Stop with Mixed Module Types
-
Optimizing the Application with r.js
- Loading with Almond.js
-
Closing Thoughts
- Keeping in Touch
- Other Books I’ve Written
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Do Well. Do Good.
Authors have earned$11,718,542writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
Recipes for Decoupling
Matthias NobackWrite software that survives
CQRS by Example
Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary- Leverage your Software Architecture skills by learning everything about CQRS in detail with lots of examples
- Develop faster applications by applying CQRS and fostering Read Models and Projections
- Learn how to apply CQRS into a brownfield project from a pragmatic approach
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
The PowerShell Scripting and Toolmaking Book
Don Jones and Jeff HicksLearn the patterns, practices, and details of PowerShell Scripting and Toolmaking from the industry's two most recognized experts on the subject.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Introduction to Data Science
Rafael A IrizarryThe demand for skilled data science practitioners in industry, academia, and government is rapidly growing. This book introduces concepts from probability, statistical inference, linear regression and machine learning and R programming skills. Throughout the book we demonstrate how these can help you tackle real-world data analysis challenges.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #3
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #5
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #10
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon...