
Recipes with Backbone Nick Gauthier and Chris Strom Recipes with Backbone Nick Gauthier and Chris Strom Table of Contents History .............................................................................................................................. vii Introduction ...................................................................................................................... viii 1. Who Should Read this Book .............................................................................. viii 2. Contact Us ............................................................................................................. ix 3. How this Book is Organized ................................................................................. ix 1. Writing Client Side Apps (Without Backbone) ............................................................. 1 1.1. Working with Dates ............................................................................................ 1 2. Writing Backbone Applications ..................................................................................... 6 2.1. Converting to Backbone.js .................................................................................. 7 2.2. Models ............................................................................................................... 10 2.3. Views ................................................................................................................. 11 2.4. Additional Reading ............................................................................................ 18 2.5. Conclusion ......................................................................................................... 18 3. Namespacing ................................................................................................................. 19 3.1. The Problem ...................................................................................................... 19 3.2. The Solution ...................................................................................................... 19 3.2.1. Alternative #1: Global Object Namespace ............................................. 19 3.2.2. Alternative #2: Javascript Function Constructor .................................... 21 3.3. Conclusion ......................................................................................................... 27 4. Organizing with Require.js .......................................................................................... 28 4.1. The Problem ...................................................................................................... 28 4.2. The Solution ...................................................................................................... 28 4.2.1. Requiring Other Things .......................................................................... 34 4.2.2. Optimization / Asset Packaging ............................................................. 35 4.3. Conclusion ......................................................................................................... 38 5. View Templates with Underscore.js ............................................................................ 39 5.1. The Problem ...................................................................................................... 39 5.2. The Solution ...................................................................................................... 39 5.2.1. Avoid Script Tag Templates .................................................................. 43 5.2.2. ERB Sucks {{ Use Mustache }} ............................................................ 45 5.2.3. Avoid Evaluation .................................................................................... 47 5.3. Conclusion ......................................................................................................... 48 6. Instantiated View .......................................................................................................... 49 6.1. Introduction ........................................................................................................ 49 iii Recipes with Backbone 6.2. The Problem ...................................................................................................... 49 6.3. The Solution ...................................................................................................... 50 6.4. Conclusion ......................................................................................................... 51 7. Collection View ............................................................................................................ 52 7.1. Introduction ........................................................................................................ 52 7.2. The Problem ...................................................................................................... 52 7.3. The Solution ...................................................................................................... 53 7.4. Conclusion ......................................................................................................... 57 8. View Signature ............................................................................................................. 58 8.1. Introduction ........................................................................................................ 58 8.2. The Problem ...................................................................................................... 58 8.3. The Solution ...................................................................................................... 58 8.3.1. What is a Signature? .............................................................................. 59 8.3.2. Signature Module ................................................................................... 59 8.3.3. A Simple Example: MD5 ....................................................................... 60 8.3.4. A Fast Example: Model Data ................................................................. 61 9. Fill-In Rendering .......................................................................................................... 63 9.1. Introduction ........................................................................................................ 63 9.2. The Problem ...................................................................................................... 63 9.3. The Solution ...................................................................................................... 64 9.4. A Quick Refactor .............................................................................................. 65 9.5. Conclusion ......................................................................................................... 66 10. Actions and Animations ............................................................................................. 67 10.1. Introduction ...................................................................................................... 67 10.2. The Problem .................................................................................................... 67 10.3. The Solution .................................................................................................... 68 10.4. Conclusion ....................................................................................................... 70 11. Reduced Models and Collections ............................................................................... 71 11.1. Introduction ...................................................................................................... 71 11.2. The Problem .................................................................................................... 71 11.3. The Solution .................................................................................................... 72 11.3.1. Simple Solution: A View ..................................................................... 72 11.3.2. Better Solution: A Reduced Collection ................................................ 73 11.4. Conclusion ....................................................................................................... 76 12. Non-REST Models ..................................................................................................... 78 12.1. Introduction ...................................................................................................... 78 iv Recipes with Backbone 12.2. The Problem .................................................................................................... 78 12.3. The Solution .................................................................................................... 78 12.3.1. Special Action ...................................................................................... 78 12.3.2. Special Persistence Layer ..................................................................... 80 12.4. Conclusion ....................................................................................................... 82 13. Changes Feed ............................................................................................................. 83 13.1. Introduction ...................................................................................................... 83 13.2. The Problem .................................................................................................... 83 13.3. Changes feed on a Collection
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages163 Page
-
File Size-