You are previewing TypeScript Design Patterns.
O'Reilly logo
TypeScript Design Patterns

Book Description

Boost your development efficiency by learning about design patterns in TypeScript

About This Book

  • This step-by-step guide will would demonstrate all the important design patterns in practice

  • This book is the only documentation on the market focusing on design patterns in TypeScript

  • This book is packed with rich examples that will improve your efficiency and encourage code reuse

  • Who This Book Is For

    If you are a TypeScript developer, this book is for you. No knowledge of design patterns is required to read this book.

    What You Will Learn

  • Understand the challenges and implications of developing an enterprise application

  • Install and configure the necessary tools in order to start developing an application

  • Identify the challenges when developing an application

  • Apply GoF patterns in an application with a testing approach

  • Use and utilize design patterns while developing a TypeScript application or during JavaScript application development

  • Reference to SOLID principles and what their benefits do to your projects

  • Apply various principles in a TypeScript application

  • Improve code quality and development speed

  • In Detail

    In programming, there are several problems that occur frequently. To solve these problems, there are various repeatable solutions that are known as design patterns. Design patterns are a great way to improve the efficiency of your programs and improve your productivity.

    This book is a collection of the most important patterns you need to improve your applications’ performance and your productivity. The journey starts by explaining the current challenges when designing and developing an application and how you can solve these challenges by applying the correct design pattern and best practices.

    Each pattern is accompanied with rich examples that demonstrate the power of patterns for a range of tasks, from building an application to code testing. We’ll introduce low-level programming concepts to help you write TypeScript code, as well as work with software architecture, best practices, and design aspects.

    Style and approach

    In this book, design patterns are explained in a step-by-step manner. All the major patterns covered will improve your understanding of TypeScript and the patterns associated with TypeScript.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. TypeScript Design Patterns
      1. TypeScript Design Patterns
      2. Credits
      3. About the Author
      4. About the Reviewer
      5. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why subscribe?
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      7. 1. Tools and Frameworks
        1. Installing the prerequisites
          1. Installing Node.js
          2. Installing TypeScript compiler
        2. Choosing a handy editor
          1. Visual Studio Code
            1. Configuring Visual Studio Code
            2. Opening a folder as a workspace
            3. Configuring a minimum build task
          2. Sublime Text with TypeScript plugin
            1. Installing Package Control
            2. Installing the TypeScript plugin
          3. Other editor or IDE options
            1. Atom with the TypeScript plugin
            2. Visual Studio
            3. WebStorm
        3. Getting your hands on the workflow
          1. Configuring a TypeScript project
            1. Introduction to tsconfig.json
            2. Compiler options
              1. target
              2. module
              3. declaration
              4. sourceMap
              5. jsx
              6. noEmitOnError
              7. noEmitHelpers
              8. noImplicitAny
              9. experimentalDecorators*
              10. emitDecoratorMetadata*
              11. outDir
              12. outFile
              13. rootDir
              14. preserveConstEnums
              15. strictNullChecks
              16. stripInternal*
              17. isolatedModules
            3. Adding source map support
          2. Downloading declarations using typings
            1. Installing typings
            2. Downloading declaration files
            3. Option "save"
          3. Testing with Mocha and Istanbul
            1. Mocha and Chai
              1. Writing tests in JavaScript
              2. Writing tests in TypeScript
            2. Getting coverage information with Istanbul
          4. Testing in real browsers with Karma
            1. Creating a browser project
            2. Installing Karma
            3. Configuring and starting Karma
          5. Integrating commands with npm
          6. Why not other fancy build tools?
        4. Summary
      8. 2. The Challenge of Increasing Complexity
        1. Implementing the basics
          1. Creating the code base
          2. Defining the initial structure of the data to be synchronized
          3. Getting data by comparing timestamps
          4. Two-way synchronizing
          5. Things that went wrong while implementing the basics
            1. Passing a data store from the server to the client does not make sense
            2. Making the relationships clear
        2. Growing features
          1. Synchronizing multiple items
            1. Simply replacing data type with an array
            2. Server-centered synchronization
              1. Synchronizing from the server to the client
              2. Synchronizing from client to server
          2. Synchronizing multiple types of data
          3. Supporting multiple clients with incremental data
            1. Updating the client side
            2. Updating server side
          4. Supporting more conflict merging
            1. New data structures
            2. Updating client side
            3. Updating the server side
          5. Things that go wrong while implementing everything
            1. Piling up similar yet parallel processes
            2. Data stores that are tremendously simplified
        3. Getting things right
          1. Finding abstraction
          2. Implementing strategies
          3. Wrapping stores
        4. Summary
      9. 3. Creational Design Patterns
        1. Factory method
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        2. Abstract Factory
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        3. Builder
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        4. Prototype
        5. Singleton
          1. Basic implementations
          2. Conditional singletons
        6. Summary
      10. 4. Structural Design Patterns
        1. Composite Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        2. Decorator Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
            1. Classical decorators
            2. Decorators with ES-next syntax
          4. Consequences
        3. Adapter Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        4. Bridge Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        5. Façade Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        6. Flyweight Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        7. Proxy Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        8. Summary
      11. 5. Behavioral Design Patterns
        1. Chain of Responsibility Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        2. Command Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        3. Memento Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        4. Iterator Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
            1. Simple array iterator
            2. ES6 iterator
          4. Consequences
        5. Mediator Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        6. Summary
      12. 6. Behavioral Design Patterns: Continuous
        1. Strategy Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        2. State Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        3. Template Method Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        4. Observer Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        5. Visitor Pattern
          1. Participants
          2. Pattern scope
          3. Implementation
          4. Consequences
        6. Summary
      13. 7. Patterns and Architectures in JavaScript and TypeScript
        1. Promise-based web architecture
          1. Promisifying existing modules or libraries
          2. Views and controllers in Express
          3. Abstraction of responses
          4. Abstraction of permissions
          5. Expected errors
            1. Defining and throwing expected errors
            2. Transforming errors
        2. Modularizing project
        3. Asynchronous patterns
          1. Writing predictable code
          2. Asynchronous creational patterns
          3. Asynchronous middleware and hooks
          4. Event-based stream parser
        4. Summary
      14. 8. SOLID Principles
        1. Single responsibility principle
          1. Example
          2. Choosing an axis
        2. Open-closed principle
          1. Example
          2. Abstraction in JavaScript and TypeScript
          3. Refactor earlier
        3. Liskov substitution principle
          1. Example
          2. The constraints of substitution
        4. Interface segregation principle
          1. Example
          2. Proper granularity
        5. Dependency inversion principle
          1. Example
          2. Separating layers
        6. Summary
      15. 9. The Road to Enterprise Application
        1. Creating an application
          1. Decision between SPA and "normal" web applications
          2. Taking team collaboration into consideration
        2. Building and testing projects
          1. Static assets packaging with webpack
            1. Introduction to webpack
            2. Bundling JavaScript
            3. Loading TypeScript
            4. Splitting code
            5. Loading other static assets
          2. Adding TSLint to projects
          3. Integrating webpack and tslint command with npm scripts
        3. Version control
          1. Git flow
            1. Main branches
            2. Supporting branches
              1. Feature branches
              2. Release branches
              3. Hotfix branches
            3. Summary of Git flow
          2. Pull request based code review
            1. Configuring branch permissions
            2. Comments and modifications before merge
          3. Testing before commits
            1. Git hooks
            2. Adding pre-commit hook automatically
        4. Continuous integration
          1. Connecting GitHub repository with Travis-CI
        5. Deployment automation
          1. Passive deployment based on Git server side hooks
          2. Proactive deployment based on timers or notifications
        6. Summary