售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Backbone.js Patterns and Best Practices
Table of Contents
Backbone.js Patterns and Best Practices
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
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
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 reflow
Re-rendering parent views
Removing parent views
Working with templates
Storing templates in an HTML file
Storing templates in a JavaScript file
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
3. Working with Models
Basic usage of models
Using the defaults property
Avoiding object references in the defaults property
Data interaction with the server
Creating a model
Updating a model
Fetching a model
Deleting a model
Validating the data
Using the Backbone.Validation plugin
Configuring validation rules
Prevalidating a model with the preValidate() method
Serializing models
Understanding the relational data model
Summary
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 filtering
Filtering a collection with a duplicate collection
Self-filtering with full data pointers
Understanding the collection of multiple model types
Summary
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
The all-in-one router
The base router
The Users module router
Summary
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
Offline storage using the Backbone.LocalStorage adapter
Summary
7. Organizing Backbone Applications – Structure, Optimize, and Deploy
Understanding the application directory structure
Working with Asynchronous Module Definition
Adding Require.js to your project
Configuring dependencies
Defining 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
Using the observer/PubSub pattern
Using the mediator pattern
Understanding view management
Understanding other important features
Summary
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
A. Books, Tutorials, and References
Books for reference
Tutorials
Unit testing
Other plugins and tutorials
B. Precompiling Templates on the Server Side
C. Organizing Templates with AMD and Require.js
Precompiling with the requirejs-tpl plugin
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜