Backbone.js Patterns and Best Practices
Год: 2014
Автор: Swarnendu De
Издательство: Packt Publishing
ISBN: 978-1-78328-358-3
Язык: Английский
Формат: PDF/EPUB/MOBI
Качество: Изначально компьютерное (eBook)
Количество страниц: 174
Описание:
In DetailBackbone.js is a super light framework that allows you to structure your JavaScript codes in an MV* fashion. This framework is an excellent tool when it comes to creating an organized and modular code base for web apps of any size or complexity. Although lightweight, Backbone.js results in lots of boilerplate. Learning the best practices and design patterns will help you avoid these problems and allow you to ensure that the best standards are followed.
Backbone.js Patterns and Best Practices is packed with examples that will help you work with Backbone.js components. It also gives solutions to common problems faced by developers. It gives a complete overview of plugin development, large scale application architecture, and unit testing as well.
Starting with a discussion of why reducing boilerplate in your JavaScript code is essential, Backbone.js Patterns and Best Practices explains how to enforce reusability in your code by creating plugins and mixins. You will learn about patterns and best practices for Backbone views, models, collections, routers, and events.
You will discover solutions to common problems that developers face through simple examples, and delve into the best open source plugins available to solve these problems when they arise. This book is an excellent collection of design and implementation patterns that will help you structure and develop complex Backbone.js applications easily.
ApproachThis is a step-by-step guide to design patterns, best practices, and solutions to common problems for Backbone.js-based application development.
Who this book is forThis book is for JavaScript developers who work with Backbone.js and want to learn the best design patterns to develop complex web applications. Basic knowledge of Backbone.js and JavaScript is essential.
Preface
Chapter 1: Reducing Boilerplate with Plugin Development
Basic components of Backbone.js
Using Underscore.js
Re-using code with extensions
Creating a base class
Developing plugins without extending base classes
Understanding JavaScript mixins
What is a mixin?
Creating classic mixins
Creating functional mixins
Caching mixin functions
Using curry to combine a function and arguments
Summary
Chapter 2: Working with Views
Basic usage of views
Understanding the el property
Listening to view events
Displaying model data with templates
Partially updating a view
Understanding nested views
Knowing when to use subviews
Avoiding multiple DOM reflw
Re-rendering parent views
Removing parent views
Working with templates
Storing templates in an HTML fie
Storing templates in a JavaScript fie
Precompiling templates
Avoiding evaluation in templates
Using template helper functions
Understanding automatic model-view data binding
Using Marionette's ItemView, CollectionView, and CompositeView
ItemView
CollectionView
Working with CompositeView
Using Layout Manager
Summary
Chapter 3: Working with Models
Basic usage of models
Using the defaults property
Avoiding object references in the defaults property
Data interaction with the server
Validating the data
Using the Backbone.Validation plugin
Confiuring validation rules
Prevalidating a model with the preValidate() method
Serializing models
Understanding the relational data model
Summary
Chapter 4: Working with Collections
Basic usage of collections
Performing data operations with collections
Fetching data from the server
Saving data to the server
Sorting a collection
Sorting a collection with multiple attributes
Filtering a collection
Performing basic fitering
Filtering a collection with a duplicate collection
Self-fitering with full data pointers
Understanding the collection of multiple model types
Summary
Chapter 5: Routing Best Practices and Subrouting
Working with routers
Best practices for working with routers
Avoiding large functional code in route methods
Instantiating views in router methods
Using regular expressions for selective routing
Subrouting – a key to organizing complex apps
Summary
Chapter 6: Working with Events, Sync, and Storage
Understanding custom events
A simple case study on custom events
Using an event dispatcher
Creating multiple event dispatchers
Using different event namespaces
Avoiding memory leaks with the listenTo() method
Overriding the Backbone.sync() method
Offlne storage using the Backbone.LocalStorage adapter
Summary
Chapter 7: Organizing Backbone Applications – Structure, Optimize, and Deploy
Understanding the application directory structure
Working with Asynchronous Module Defiition
Adding Require.js to your project
Confiuring dependencies
Defiing a module
Creating application architecture
Managing a project directory
Organizing code with AMD
Setting up an application
Using the module pattern
Managing objects and module communication
Understanding view management
Understanding other important features
Summary
Chapter 8: Unit Test, Stub, Spy, and Mock Your App
Understanding why unit testing is important
Testing with QUnit
Performing a basic test case
Understanding the QUnit module (), setup (), and teardown () methods
Testing Backbone.js components with QUnit
Using test spies, stubs, and mocks with SinonJS
Testing with spies
Testing with stubs
Testing with mocks
Difference between mocks and stubs
Summary
Appendix A: Books, Tutorials, and References
Books for reference
Tutorials
Unit testing
Other plugins and tutorials
Appendix B: Precompiling Templates on the Server Side
Appendix C: Organizing Templates with AMD and Require.js
Precompiling with the requirejs-tpl plugin
Index
Внимание! К данной книге имеются исходники кода, их можно найти на сайте O'Reilly