logo资料库

Single Page Web Applications JavaScript end-to-end.pdf

第1页 / 共433页
第2页 / 共433页
第3页 / 共433页
第4页 / 共433页
第5页 / 共433页
第6页 / 共433页
第7页 / 共433页
第8页 / 共433页
资料共433页,剩余部分请下载后查看
Single Page Web Applications
brief contents
contents
foreword
preface
acknowledgments
about this book
Roadmap
Audience
Code conventions and downloads
Software and hardware requirements
Author Online
About the authors
about the cover illlustration
Part 1: Introducing SPAs
Chapter 1: Our first single page application
1.1 Definition, a little history, and some focus
1.1.1 A little history
1.1.2 What took JavaScript SPAs so long?
1.1.3 Our focus
1.2 Build our first SPA
1.2.1 Define the goal
1.2.2 Start the file structure
1.2.3 Set up Chrome Developer Tools
1.2.4 Develop the HTML and CSS
1.2.5 Add the JavaScript
1.2.6 Inspect our application using Chrome Developer Tools
1.3 The user benefits of a well-written SPA
1.4 Summary
Chapter 2: Reintroducing JavaScript
2.1 Variable scope
2.2 Variable hoisting
2.3 Advanced variable hoisting and the execution context object
2.3.1 Hoisting
2.3.2 Execution context and the execution context object
2.4 The scope chain
2.5 JavaScript objects and the prototype chain
2.5.1 The prototype chain
2.6 Functions—a deeper look
2.6.1 Functions and anonymous functions
2.6.2 Self-executing anonymous functions
2.6.3 The module pattern—bringing private variables to JavaScript
2.6.4 Closures
2.7 Summary
Part 2: The SPA client
Chapter 3: Develop the Shell
3.1 Grok the Shell
3.2 Set up the files and namespaces
3.2.1 Create the file structure
3.2.2 Write the application HTML
3.2.3 Create the root CSS namespace
3.2.4 Create the root JavaScript namespace
3.3 Create the feature containers
3.3.1 Pick a strategy
3.3.2 Write the Shell HTML
3.3.3 Write the Shell CSS
3.4 Render the feature containers
3.4.1 Convert the HTML to JavaScript
3.4.2 Add an HTML template to our JavaScript
3.4.3 Write the Shell stylesheet
3.4.4 Direct the application to use the Shell
3.5 Manage the feature containers
3.5.1 Write a method to extend or retract the chat slider
3.5.2 Add the chat slider click event handler
3.6 Manage application state
3.6.1 Understand the behavior browser users expect
3.6.2 Pick a strategy to manage history controls
3.6.3 Change the anchor when a history event occurs
3.6.4 Use the anchor to drive the application state
3.7 Summary
Chapter 4: Add feature modules
4.1 The feature module strategy
4.1.1 A comparison with third-party modules
4.1.2 Feature modules and fractal MVC pattern
4.2 Set up feature module files
4.2.1 Plan the file structure
4.2.2 Populate the files
4.2.3 What we’ve wrought
4.3 Design method APIs
4.3.1 The anchor interface pattern
4.3.2 Chat configuration APIs
4.3.3 The Chat initialization API
4.3.4 The Chat setSliderPosition API
4.3.5 Configuration and initialization cascade
4.4 Implement the feature API
4.4.1 The stylesheets
4.4.2 Modify Chat
4.4.3 Clean up the Shell
4.4.4 Walk through the execution
4.5 Add frequently needed methods
4.5.1 The removeSlider method
4.5.2 The handleResize method
4.6 Summary
Chapter 5: Build the Model
5.1 Understand the Model
5.1.1 What we’re going to build
5.1.2 What the Model does
5.1.3 What the Model does not do
5.2 Set up the Model and other files
5.2.1 Plan the file structure
5.2.2 Populate the files
5.2.3 Use the unified touch-mouse library
5.3 Design the people object
5.3.1 Design the person objects
5.3.2 Design the people object API
5.3.3 Document the people object API
5.4 Build the people object
5.4.1 Create a fake people list
5.4.2 Start the people object
5.4.3 Finish the people object
5.4.4 Test the people object API
5.5 Enable sign-in and sign-out in the Shell
5.5.1 Design the user sign-in experience
5.5.2 Update the Shell JavaScript
5.5.3 Update the Shell stylesheet
5.5.4 Test sign-in and sign-out using the UI
5.6 Summary
Chapter 6: Finish the Model and Data modules
6.1 Design the chat object
6.1.1 Design methods and events
6.1.2 Document the chat object API
6.2 Build the chat object
6.2.1 Start the chat object with the join method
6.2.2 Update Fake to respond to chat.join
6.2.3 Test the chat.join method
6.2.4 Add messaging to the chat object
6.2.5 Update Fake to emulate messaging
6.2.6 Test chat messaging
6.3 Add Avatar support to the Model
6.3.1 Add Avatar support to the chat object
6.3.2 Modify Fake to emulate avatars
6.3.3 Test avatar support
6.3.4 Test-driven development
6.4 Complete the Chat feature module
6.4.1 Update the Chat JavaScript
6.4.2 Update the stylesheets
6.4.3 Test the Chat UI
6.5 Create the Avatar feature module
6.5.1 Create the Avatar JavaScript
6.5.2 Create the Avatar stylesheet
6.5.3 Update the Shell and the browser document
6.5.4 Test the Avatar feature module
6.6 Data binding and jQuery
6.7 Create the Data module
6.8 Summary
Part 3: The SPA server
Chapter 7: The web server
7.1 The role of the server
7.1.1 Authentication and authorization
7.1.2 Validation
7.1.3 Preservation and synchronization of data
7.2 Node.js
7.2.1 Why Node.js?
7.2.2 Create ‘Hello World’ using Node.js
7.2.3 Install and use Connect
7.2.4 Add Connect middleware
7.2.5 Install and use Express
7.2.6 Add Express middleware
7.2.7 Use environments with Express
7.2.8 Serving static files with Express
7.3 Advanced routing
7.3.1 User CRUD routes
7.3.2 Generic CRUD routing
7.3.3 Place routing in a separate Node.js module
7.4 Adding authentication and authorization
7.4.1 Basic Authentication
7.5 Web sockets and Socket.IO
7.5.1 Simple Socket.IO
7.5.2 Socket.IO and messaging servers
7.5.3 Updating JavaScript with Socket.IO
7.6 Summary
Chapter 8: The server database
8.1 The role of the database
8.1.1 Select the data store
8.1.2 Eliminate data transformations
8.1.3 Move the logic where you need it
8.2 An introduction to MongoDB
8.2.1 Document-oriented storage
8.2.2 Dynamic document structure
8.2.3 Get started with MongoDB
8.3 Use the MongoDB driver
8.3.1 Prepare the project files
8.3.2 Install and connect to MongoDB
8.3.3 Use MongoDB CRUD methods
8.3.4 Add CRUD to the server application
8.4 Validate client data
8.4.1 Validate the object type
8.4.2 Validate the object
8.5 Create a separate CRUD module
8.5.1 Prepare the file structure
8.5.2 Move CRUD into its own module
8.6 Build the Chat module
8.6.1 Start the chat module
8.6.2 Create the adduser message handler
8.6.3 Create the updatechat message handler
8.6.4 Create disconnect message handlers
8.6.5 Create the updateavatar message handler
8.7 Summary
Chapter 9: Readying our SPA for production
9.1 Optimize our SPA for search engines
9.1.1 How Google crawls an SPA
9.2 The cloud and third-party services
9.2.1 Site analytics
9.2.2 Logging client-side errors
9.2.3 Content delivery networks
9.3 Caching and cache busting
9.3.1 Caching opportunities
9.3.2 Web storage
9.3.3 HTTP caching
9.3.4 Server caching
9.3.5 Database query caching
9.4 Summary
appendix A: JavaScript coding standard
A.1 Why we need a coding standard
A.2 Code layout and comments
A.2.1 Lay out your code for readability
A.2.2 Comment to explain and document
A.3 Variable names
A.3.1 Reduce and improve comments with a naming convention
A.3.2 Use naming guidelines
A.3.3 Put the guidelines to use
A.4 Variable declaration and assignment
A.5 Functions
A.6 Namespaces
A.7 File names and layout
A.8 Syntax
A.8.1 Labels
A.8.2 Statements
A.8.3 Other syntax
A.9 Validating code
A.9.1 Install JSLint
A.9.2 Configure JSLint
A.9.3 Use JSLint
A.10 A template for modules
A.11 Summary
appendix B: Testing an SPA
B.1 Set up test modes
B.2 Select a test framework
B.3 Set up nodeunit
B.4 Create the test suite
B.4.1 Get Node.js to load our modules
B.4.2 Set up a single nodeunit test
B.4.3 Create our first real test
B.4.4 Map the events and tests
B.4.5 Create the test suite
B.5 Adjust SPA modules for tests
B.6 Summary
index
Symbols
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
JavaScript end-to-end Michael S. Mikowski Josh C. Powell FOREWORD BY Gregory D. Benson M A N N I N G
Single Page Web Applications Download from Wow! eBook
Download from Wow! eBook
Single Page Web Applications JAVASCRIPT END-TO-END MICHAEL S. MIKOWSKI JOSH C. POWELL M A N N I N G Shelter Island Download from Wow! eBook
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2014 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. 20 Baldwin Road Shelter Island, NY 11964 Development editor: Karen Miller Technical proofreader: John J. Ryan III Production editor: Janet Vail Copyeditor: Benjamin Berg Proofreader: Toma Mulligan Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617290756 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 18 17 16 15 14 13 Download from Wow! eBook
To my parents, wife, and children. You have taught me so much, and I love you all. —M.S.M. To my wife, Marianne. Thank you for your extraordinary patience with all the time I took writing the book. I love you. —J.C.P. Download from Wow! eBook
Download from Wow! eBook
brief contents PART 1 INTRODUCING SPAS . .......................................................1 1 ■ Our first single page application 3 2 ■ Reintroducing JavaScript 23 PART 2 THE SPA CLIENT ...........................................................59 3 ■ Develop the Shell 61 4 ■ Add feature modules 95 5 ■ Build the Model 139 6 ■ Finish the Model and Data modules 178 PART 3 THE SPA SERVER .........................................................227 7 ■ The web server 229 8 ■ The server database 265 9 ■ Readying our SPA for production 313 vii Download from Wow! eBook
分享到:
收藏