Chapter 1. A better way to build apps
Chapter 2. My fridge! A reactive game
Listing 2.1. General layout styles
Listing 2.2. Skeleton template structure
Listing 2.3. Looping through products in the productsList template with the each helper
Listing 2.4. Template for each productListItem
Listing 2.5. Looping through each product inside the fridge template
Listing 2.6. Declaring a products collection on the client and server
Listing 2.7. Setting up a products helper for the fridge template
Listing 2.8. Setting up a products helper for the productList template
Listing 2.9. Adding a defined dataset to the database upon server start
Listing 2.10. Loading jQuery-UI from a CDN
Listing 2.11. Declaring fridge as a droppable target and updating the product location
Chapter 3. Working with templates
Listing 3.1. Rendered HTML from template
Listing 3.2. Double-braced template tags
Listing 3.3. JavaScript code for a helper called name
Listing 3.4. Full profile page template
Listing 3.5. Splitting the profile page template
Listing 3.6. Inserting subtemplates dynamically with helpers
Listing 3.7. Using an if block
Listing 3.8. Using an unless block
Listing 3.9. Using else in an if block
Listing 3.10. Using the #each tag
Listing 3.11. Using the #with tag
Listing 3.12. A profile template using different local helpers
Listing 3.13. Using global helpers to determine array length
Listing 3.14. Custom block helpers with Template.contentBlock
Listing 3.15. Using Template.elseBlock
Listing 3.16. Moving template logic into a JavaScript helper
Listing 3.17. Event map for layout template
Listing 3.18. Listening for events in a subtemplate
Listing 3.19. Stopping event propagation within an event map
Listing 3.20. Preventing the browser’s default behavior
Listing 3.21. Initializing a jQuery plug-in to create a datepicker on an input element
Chapter 4. Working with data
Listing 4.1. Setting up a reactive context using template helpers
Listing 4.2. Basic template structure in client/templates.html
Listing 4.3. Collection declaration in collections/houses.js
Listing 4.4. Adding fixtures in server/server.js
Listing 4.5. Using the Session object
Listing 4.6. Drop-down list code in the selectHouse template
Listing 4.7. JavaScript code for selecting houses
Listing 4.8. Using Tracker.autorun() to print a Session variable to the console
Listing 4.9. Limiting the fields returned to the drop-down list
Listing 4.10. Returning a database document to a template based on ID
Listing 4.11. Template code for showing a house with all plants
Listing 4.12. Event map for watering the plants
Listing 4.13. Template helper for disabling the Done button
Listing 4.14. Extended event map for adding a last-visited date
Listing 4.15. Adding the lastvisit timestamp to the showHouse template
Listing 4.16. Adding new houses using a form
Listing 4.17. Event map for adding a new house
Listing 4.18. Adding a delete button to remove houses from the database
Chapter 5. Fully reactive editing
Listing 5.1. Setting up a local collection
Listing 5.2. Adding a house to the local staging collection using the change event
Listing 5.3. Global helper that returns the edit object
Listing 5.4. Setting the data context to the global selectedHouse helper using {{#with}}
Listing 5.5. Template code for displaying multiple plants in the HTML form
Listing 5.6. Using Underscore.js to add an index attribute to arrays of objects
Listing 5.7. Adding an index to plants using template helpers
Listing 5.8. Adding index information to the plantFieldset template
Listing 5.9. Wrapper function for performing updates to the LocalHouse collection
Listing 5.10. Event map for updating the house name
Listing 5.11. Event map for adding a new plant
Listing 5.12. Saving the staging document to the database with a timestamp
Listing 5.13. Event map for updating plant properties
Listing 5.15. Using a template for displaying notifications
Listing 5.16. Adding status to the update modifiers
Listing 5.17. Helper that displays notifications from a Session variable
Chapter 6. Users, authentications, and permissions
Listing 6.1. Adding loginButtons
Listing 6.2. A single user document stored inside the users collection
Listing 6.3. Configuring registration to ask for both username and email
Listing 6.4. Adding profile information to new users
Listing 6.5. Configuring an SMTP server in server/smtp.js
Listing 6.6. Sending verification emails upon user creation
Listing 6.7. Customizing the accounts email templates
Listing 6.8. Inserting Facebook OAuth configuration as a fixture in server/server.js
Listing 6.9. The user document when signing up via Facebook
Listing 6.10. Adding Facebook information to the user profile
Listing 6.11. Using allow for a Messages collection
Listing 6.12. Allowing logged-in users to insert new messages
Listing 6.13. deny inserts with missing or additional fields
Listing 6.14. Deny message removal for everyone but the recipient
Chapter 7. Exchanging data
Listing 7.1. A simple server-side publication
Listing 7.2. Using a template-level subscription with a loading indicator
Listing 7.3. Adding parameters to a publication
Listing 7.4. Subscribing to a publication with parameters
Listing 7.5. Adding an event handler to increase the limit by 10
Listing 7.6. Aggregation inside a publication
Listing 7.7. Observing changes in a collection
Listing 7.8. Using observeChanges to update aggregated data
Listing 7.9. Sending only the data a user is allowed to see
Listing 7.10. Aggregation of a user’s documents
Listing 7.11. A method call from the client
Listing 7.12. Using a method to create a new document
Listing 7.13. Console message for unchecked values in methods
Chapter 8. Routing using Iron.Router
Listing 8.1. Initial templates for the community application
Listing 8.2. Setting up different routes
Listing 8.3. Moving layout-specific markup into a common layout template
Listing 8.4. Setting a layout inside the route function
Listing 8.5. Rendering a template inside a named yield with template helpers
Listing 8.6. Rendering a template inside a named yield using JavaScript
Listing 8.7. Setting the data context with Iron.Router
Listing 8.8. Publishing the profiles collection with a one-second delay
Listing 8.9. Defining a route’s behavior by options only
Listing 8.10. Subscribing based on a route
Listing 8.11. Waiting on individual profile subscriptions
Listing 8.12. Using named routes
Listing 8.13. Using the linkTo block helper to render anchor elements
Listing 8.14. A global template helper that highlights an active link
Listing 8.15. Waiting for external libraries to load
Listing 8.16. Using an Iron.Router controller
Listing 8.17. Routes declaration using controllers
Listing 8.18. Adding a hook to a RouteController
Listing 8.19. Requiring a logged-in user for a specific route
Listing 8.20. Creating a reusable Iron.Router plug-in
Chapter 9. The package system
Listing 9.1. Adding npm packages via packages.json
Listing 9.2. Using the gravatar npm module from a Meteor method
Listing 9.3. Defining the notifications package
Listing 9.4. Defining unit tests for the notifications package
Listing 9.5. Template code for the notifications package
Listing 9.6. Template helpers and events for the notifications package
Listing 9.7. Exposing package functionality via the Notifications global
Listing 9.8. Adding a notification via the notifications package
Chapter 10. Advanced server methods
Listing 10.1. Blocking synchronous code in methods
Listing 10.2. Nonblocking method with simulated delay
Listing 10.3. The pyramid of doom
Listing 10.4. Using fibers to avoid the pyramid of doom
Listing 10.5. Calling a function using wrapAsync
Listing 10.6. Sequentially executing methods
Listing 10.7. Using unblock to let other functions continue
Listing 10.8. Using Meteor.userId() in a callback for a method
Listing 10.9. Using Meteor.userId() in a bound callback for a method
Listing 10.10. Querying an external API using a synchronous method
Listing 10.11. Dedicated function for asynchronous API calls
Listing 10.12. Updated method for making asynchronous API calls
Listing 10.13. Template for making API calls and displaying errors
Listing 10.14. Template helpers for making API calls
Listing 10.15. Template code for uploading files
Listing 10.16. Code for publishing and subscribing to a single file
Listing 10.17. Using FileReader to upload a file
Listing 10.18. saveFile method for storing files in a collection
Chapter 11. Building and debugging
Listing 11.1. Sample style file using the LESS preprocessor
Listing 11.2. Registering a build plug-in with CoffeeScript support in package.json
Listing 11.3. Skeleton for transpiling TypeScript to JavaScript during the build
Listing 11.4. Setting breakpoints using debugger;
Listing 11.5. Setting configuration options for applications via settings.json
Listing 11.6. Using Meteor.settings with values from a JSON configuration file
Listing 11.7. Sample App.info() for a mobile app
Listing 11.8. Setting up icons and launch screens in mobile.config.js
Listing 11.9. Declaring URL access rules in mobile.config.js
Listing 11.10. Configuring app behavior and Cordova plug-ins
Listing 11.11. Adding the Cordova dialogs plug-in to a change event
Chapter 12. Going into production
Appendix C. Setting up nginx
Listing C.1. nginx site configuration