Understanding single-page web applications Emmit A. Scott, Jr. F Burke Holland OREWORD BY M A N N I N G SPA Design and Architecture Licensed to Mark Watson <[email protected]> ii Licensed to Mark Watson <[email protected]> SPA Design and Architecture Understanding single-page web applications EMMIT A. SCOTT, JR. MANNING SHELTER ISLAND Licensed to Mark Watson <[email protected]> iv 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 761 Shelter Island, NY 11964 Email: [email protected] ©2016 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 elemental chlorine. Manning Publications Co. Development editor: Dan Maharry 20 Baldwin Road Technical development editor: Joel Kotarski PO Box 761 Technical proofreaders: Andrew Gibson Shelter Island, NY 11964 Jean-François Morin Copyeditor: Sharon Wilkey Proofreader: Linda Recktenwald Typesetter: Marija Tudor Cover designer: Marija Tudor ISBN: 9781617292439 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 20 19 18 17 16 15 Licensed to Mark Watson <[email protected]> To my three beautiful children, Ana Carolina, David, and Sofía. Thanks for all the smiles, hugs, and unconditional love. You are forever in my heart. Licensed to Mark Watson <[email protected]> vi Licensed to Mark Watson <[email protected]> brief contents PART 1 THE BASICS ..................................................................1 1 ■ What is a single-page application? 3 2 ■ The role of MV* frameworks 22 3 ■ Modular JavaScript 52 PART 2 CORE CONCEPTS ........................................................83 4 ■ Navigating the single page 85 5 ■ View composition and layout 106 6 ■ Inter-module interaction 129 7 ■ Communicating with the server 156 8 ■ Unit testing 186 9 ■ Client-side task automation 209 appendix A Employee directory example walk-through 229 appendix B Review of the XMLHttpRequest API 259 appendix C Chapter 7 server-side setup and summary 266 appendix D Installing Node.js and Gulp.js 277 vii Licensed to Mark Watson <[email protected]> viii BRIEF CONTENTS Licensed to Mark Watson <[email protected]> contents foreword xv preface xvii acknowledgments xviii about this book xix about the cover illustration xxiii PART 1 THE BASICS 1 1 What is a single-page application? 3 1.1 SPA in a nutshell 4 No browser refreshes 7 ■ Presentation logic in the client 7 Server transactions 7 1.2 A closer look 8 An SPA starts with a shell 8 ■ From traditional pages to views 9 ■ The birth of a view 10 ■ View swapping for zero reload navigation 11 ■ Fluidity through dynamic updates 12 1.3 Benefits of SPAs over traditional web applications 12 1.4 Rethinking what you already know 14 1.5 Ingredients of a well-designed SPA 15 Organizing your project 15 ■ Creating a maintainable, loosely coupled UI 17 ■ Using JavaScript modules 18 ■ Performing SPA navigation 19 ■ Creating view composition and layout 19 ■ Enabling module communication 20 ix Licensed to Mark Watson <[email protected]>
Description: