0%

Book Description

Now that Angular 2 is available, you may be tempted to scrap the single-page enterprise application you developed with the original AngularJS framework and go with either the newer version or perhaps the React library. But even if your original codebase is difficult to understand and maintain, it still holds significant value. Rather than start over, you can polish this diamond in the rough through refactoring.

In this report, website development veteran Corinna Cohn shows you how to refactor your existing AngularJS code so it is easier to read, maintain, and expand with new features. You’ll learn how to improve the quality of your code—without altering its observable behavior—through unit testing and web application best practices.

  • Learn unit-testing principles and why testing is helpful for refactoring
  • Get best practices for writing web applications and reorganizing project files
  • Simplify overloaded views and move complicated application logic out of templates
  • Learn the role that services, filters, and directives play in creating clean Angular applications
  • Understand how and why to refactor high-risk Angular controllers
  • Compare new and outmoded patterns for developing with modern JavaScript frameworks

Table of Contents

  1. 1. Refactoring AngularJS
    1. Why Refactoring?
  2. 2. Refactoring for Angular
    1. Overview of Changes Between AnguarJS and Angular
      1. Changes to Angular Architecture
    2. Factors to Consider When Upgrading to Angular
    3. Summary
  3. 3. Unit Testing and Refactoring
    1. Unit Testing and Refactoring
      1. Why Is Test-Driven Development So Important?
    2. Writing Unit Tests in Angular
      1. Running Unit Tests with Karma
    3. Integration Tests
    4. Summary
  4. 4. Refactoring and Best Practices
    1. Use a Style Guide
    2. Use an IDE that Supports EditorConfig
    3. Use Automated Tools to Build and Validate Your Applications
    4. Code and Style Linters
    5. Summary
  5. 5. Refactoring Through Reorganization
    1. Organizing the Files of the Project
    2. Grouping Related Features into Angular Modules
      1. Wrapping Third-Party Libraries
    3. Summary
  6. 6. Views and Templates
    1. Use ng-include to Simplify Overloaded Views
    2. Remove Application Logic from Templates
    3. Move Behavior onto the Model
    4. Summary
  7. 7. Services, Filters, and Components
    1. Use Services to Contain Business and Presentation Logic
    2. Use Filters for Reusable Transformation of Data
      1. Filters and Performance
    3. Refactoring into Directives and Components
    4. The AngularJS Component
    5. Summary
  8. 8. Refactoring Controllers
    1. Controllers Contain the Highest-Risk Code
    2. Refactoring a Controller
      1. First Pass
      2. Second Pass
      3. Third Pass
    3. Summary
  9. 9. Refactoring to Patterns
    1. Rich Domain Models Locate Behavior on the Object Itself
    2. Flux Pattern: Unidirectional Data Flows
    3. Page Controller Is an Antipattern in Angular
    4. Summary
  10. Further Reading
18.221.59.245