万本电子书0元读

万本电子书0元读

顶部广告

TypeScript: Modern JavaScript Development电子书

售       价:¥

9人正在读 | 0人评论 9.8

作       者:Remo H. Jansen

出  版  社:Packt Publishing

出版时间:2016-12-01

字       数:859.4万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Leverage the features of TypeScript to boost your development skills and create captivating applications About This Book Learn how to develop modular, scalable, maintainable, and adaptable web applications by taking advantage of TypeScript Explore techniques to use TypeScript alongside other leading tools such as Angular 2, React, and Node.js Focusing on design patterns in TypeScript, this step-by-step guide demonstrates all the important design patterns in practice Who This Book Is For This Learning Path is for intermediate-level JavaScript developers who want to use TypeScript to build beautiful web applications and fun projects. No prior knowledge of TypeScript is required, but a basic understanding of jQuery is expected. This Learning Path is also for experienced TypeScript developers who want to take their skills to the next level, and also for web developers who wish to make the most of TypeScript. What You Will Learn Understand the key TypeScript language features and runtime Install and configure the necessary tools in order to start developing an application Create object-oriented code that adheres to the SOLID principles Develop robust applications with testing (Mocha, Chai, and SinonJS) Apply GoF patterns in an application with a testing approach Identify the challenges when developing an application Migrate JavaScript codebases to TypeScript to improve your workflow Utilize System.JS and Webpack to load *s and their dependencies Develop high performance server-side applications to run within Node.js In Detail TypeScript is an open source and cross-platform typed superset of JavaScript that compiles to plain JavaScript that runs in any browser or any host. TypeScript adds optional static types, classes, and modules to JavaScript, to enable great tooling and better structuring of large JavaScript applications. Through this three-module learning path, you’ll learn the ins-and-outs of TypeScript for building more robust software. The first module gets you started with TypeScript and helps you understand the basics of TypeScript and automation tools. Get a detailed de*ion of function, generics, callbacks, and promises, and discover the object-oriented features and memory management functionality of TypeScript. The next module 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. You will be introduced to low-level programming concepts to help you write TypeScript code, as well as working with software architecture, best practices, and design aspects. The final module will help you build a complete single page app with Angular 2, create a neat mobile app using NativeScript, and even build a Pac Man game with TypeScript. As if the fun wasn't enough, you'll also find out how to migrate your legacy codebase from JavaScript to TypeScript. By the end of this Learning Path, you will be able to take your skills up a notch and develop full-fledged web applications using the latest features of the TypeScript. This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products: Learning TypeScript by Remo H. Jansen TypeScript Design Patterns by Vilic Vane TypeScript Blueprints by Ivo Gabe de Wolff Style and approach This is a step-by-step, practical guide covering the fundamentals of TypeScript with practical examples. The end-to-end projects included in this book will give you ready-to-implement solutions for your business scenario, showcasing the depth and robustness of TypeScript.
目录展开

TypeScript: Modern JavaScript Development

Table of Contents

TypeScript: Modern JavaScript Development

TypeScript: Modern JavaScript Development

Credits

Preface

What this learning path covers

What you need for this learning path

Who this learning path is for

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Module 1

1. Introducing TypeScript

The TypeScript architecture

Design goals

TypeScript components

TypeScript language features

Types

Optional static type notation

Variables, basic types, and operators

Var, let, and const

Union types

Type guards

Type aliases

Ambient declarations

Arithmetic operators

Comparison operators

Logical operators

Bitwise operators

Assignment operators

Flow control statements

The single-selection structure (if)

The double-selection structure (if…else)

The inline ternary operator (?)

The multiple-selection structure (switch)

The expression is tested at the top of the loop (while)

The expression is tested at the bottom of the loop (do…while)

Iterate on each object's properties (for…in)

Counter controlled repetition (for)

Functions

Classes

Interfaces

Namespaces

Putting everything together

Summary

2. Automating Your Development Workflow

A modern development workflow

Prerequisites

Node.js

Atom

Git and GitHub

Source control tools

Package management tools

npm

Bower

tsd

Task runners

Checking the quality of the TypeScript code

Compiling the TypeScript code

Optimizing a TypeScript application

Managing the Gulp tasks' execution order

Test runners

Synchronized cross-device testing

Continuous Integration tools

Scaffolding tools

Summary

3. Working with Functions

Working with functions in TypeScript

Function declarations and function expressions

Function types

Functions with optional parameters

Functions with default parameters

Functions with rest parameters

Function overloading

Specialized overloading signatures

Function scope

Immediately invoked functions

Generics

Tag functions and tagged templates

Asynchronous programming in TypeScript

Callbacks and higher-order functions

Arrow functions

Callback hell

Promises

Generators

Asynchronous functions – async and await

Summary

4. Object-Oriented Programming with TypeScript

SOLID principles

Classes

Interfaces

Association, aggregation, and composition

Association

Aggregation

Composition

Inheritance

Mixins

Generic classes

Generic constraints

Multiple types in generic type constraints

The new operator in generic types

Applying the SOLID principles

The Liskov substitution principle

The interface segregation principle

The dependency inversion principle

Namespaces

Modules

ES6 modules – runtime and design time

External modules – design time only

AMD modules – runtime only

CommonJS modules – runtime only

UMD modules – runtime only

SystemJS modules – runtime only

Circular dependencies

Summary

5. Runtime

The environment

The runtime

Frames

Stack

Queue

Heap

The event loop

The this operator

The this operator in the global context

The this operator in a function context

The call, apply, and bind methods

Prototypes

Instance properties versus class properties

Prototypal inheritance

The prototype chain

Accessing the prototype of an object

The new operator

Closures

Static variables with closures

Private members with closures

Summary

6. Application Performance

Prerequisites

Performance and resources

Performance metrics

Availability

The response time

Processing speed

Latency

Bandwidth

Scalability

Performance analysis

Network performance analysis

Network performance and user experience

Network performance best practices and rules

GPU performance analysis

Frames per second (FPS)

CPU performance analysis

Memory performance analysis

The garbage collector

Performance automation

Performance optimization automation

Performance monitoring automation

Performance testing automation

Exception handling

The Error class

The try…catch statements and throw statements

Summary

7. Application Testing

Software testing glossary

Assertions

Specs

Test cases

Suites

Spies

Dummies

Stubs

Mocks

Test coverage

Prerequisites

Gulp

Karma

Istanbul

Mocha

Chai

Sinon.JS

Type definitions

PhantomJS

Selenium and Nightwatch.js

Testing planning and methodologies

Test-driven development

Behavior-driven development (BDD)

Tests plans and test types

Setting up a test infrastructure

Building the application with Gulp

Running the unit test with Karma

Running E2E tests with Selenium and Nightwatch.js

Creating test assertions, specs, and suites with Mocha and Chai

Testing the asynchronous code

Asserting exceptions

TDD versus BDD with Mocha and Chai

Test spies and stubs with Sinon.JS

Spies

Stubs

Creating end-to-end tests with Nightwatch.js

Generating test coverage reports

Summary

8. Decorators

Prerequisites

Annotations and decorators

The class decorators

The method decorators

The property decorators

The parameter decorators

The decorator factory

Decorators with arguments

The reflection metadata API

Summary

9. Application Architecture

The single-page application architecture

The MV* architecture

Common components and features in the MV* frameworks

Models

Collections

Item views

Collection views

Controllers

Events

Router and hash (#) navigation

Mediator

Dispatcher

Client-side rendering and Virtual DOM

User interface data binding

One-way data binding

Two-way data binding

Data flow

Web components and shadow DOM

Choosing an application framework

Writing an MVC framework from scratch

Prerequisites

Application events

Mediator

Application

Route

Event emitter

Router

Dispatcher

Controller

Model and model settings

View and view settings

Framework

Summary

10. Putting Everything Together

Prerequisites

The application's requirements

The application's data

The application's architecture

The application's file structure

Configuring the automated build

The application's layout

Implementing the root component

Implementing the market controller

Implementing the NASDAQ model

Implementing the NYSE model

Implementing the market view

Implementing the market template

Implementing the symbol controller

Implementing the quote model

Implementing the symbol view

Implementing the chart model

Implementing the chart view

Testing the application

Preparing the application for a production release

Summary

2. Module 2

1. Tools and Frameworks

Installing the prerequisites

Installing Node.js

Installing TypeScript compiler

Choosing a handy editor

Visual Studio Code

Configuring Visual Studio Code

Opening a folder as a workspace

Configuring a minimum build task

Sublime Text with TypeScript plugin

Installing Package Control

Installing the TypeScript plugin

Other editor or IDE options

Atom with the TypeScript plugin

Visual Studio

WebStorm

Getting your hands on the workflow

Configuring a TypeScript project

Introduction to tsconfig.json

Compiler options

target

module

declaration

sourceMap

jsx

noEmitOnError

noEmitHelpers

noImplicitAny

experimentalDecorators*

emitDecoratorMetadata*

outDir

outFile

rootDir

preserveConstEnums

strictNullChecks

stripInternal*

isolatedModules

Adding source map support

Downloading declarations using typings

Installing typings

Downloading declaration files

Option "save"

Testing with Mocha and Istanbul

Mocha and Chai

Writing tests in JavaScript

Writing tests in TypeScript

Getting coverage information with Istanbul

Testing in real browsers with Karma

Creating a browser project

Installing Karma

Configuring and starting Karma

Integrating commands with npm

Why not other fancy build tools?

Summary

2. The Challenge of Increasing Complexity

Implementing the basics

Creating the code base

Defining the initial structure of the data to be synchronized

Getting data by comparing timestamps

Two-way synchronizing

Things that went wrong while implementing the basics

Passing a data store from the server to the client does not make sense

Making the relationships clear

Growing features

Synchronizing multiple items

Simply replacing data type with an array

Server-centered synchronization

Synchronizing from the server to the client

Synchronizing from client to server

Synchronizing multiple types of data

Supporting multiple clients with incremental data

Updating the client side

Updating server side

Supporting more conflict merging

New data structures

Updating client side

Updating the server side

Things that go wrong while implementing everything

Piling up similar yet parallel processes

Data stores that are tremendously simplified

Getting things right

Finding abstraction

Implementing strategies

Wrapping stores

Summary

3. Creational Design Patterns

Factory method

Participants

Pattern scope

Implementation

Consequences

Abstract Factory

Participants

Pattern scope

Implementation

Consequences

Builder

Participants

Pattern scope

Implementation

Consequences

Prototype

Singleton

Basic implementations

Conditional singletons

Summary

4. Structural Design Patterns

Composite Pattern

Participants

Pattern scope

Implementation

Consequences

Decorator Pattern

Participants

Pattern scope

Implementation

Classical decorators

Decorators with ES-next syntax

Consequences

Adapter Pattern

Participants

Pattern scope

Implementation

Consequences

Bridge Pattern

Participants

Pattern scope

Implementation

Consequences

Façade Pattern

Participants

Pattern scope

Implementation

Consequences

Flyweight Pattern

Participants

Pattern scope

Implementation

Consequences

Proxy Pattern

Participants

Pattern scope

Implementation

Consequences

Summary

5. Behavioral Design Patterns

Chain of Responsibility Pattern

Participants

Pattern scope

Implementation

Consequences

Command Pattern

Participants

Pattern scope

Implementation

Consequences

Memento Pattern

Participants

Pattern scope

Implementation

Consequences

Iterator Pattern

Participants

Pattern scope

Implementation

Simple array iterator

ES6 iterator

Consequences

Mediator Pattern

Participants

Pattern scope

Implementation

Consequences

Summary

6. Behavioral Design Patterns: Continuous

Strategy Pattern

Participants

Pattern scope

Implementation

Consequences

State Pattern

Participants

Pattern scope

Implementation

Consequences

Template Method Pattern

Participants

Pattern scope

Implementation

Consequences

Observer Pattern

Participants

Pattern scope

Implementation

Consequences

Visitor Pattern

Participants

Pattern scope

Implementation

Consequences

Summary

7. Patterns and Architectures in JavaScript and TypeScript

Promise-based web architecture

Promisifying existing modules or libraries

Views and controllers in Express

Abstraction of responses

Abstraction of permissions

Expected errors

Defining and throwing expected errors

Transforming errors

Modularizing project

Asynchronous patterns

Writing predictable code

Asynchronous creational patterns

Asynchronous middleware and hooks

Event-based stream parser

Summary

8. SOLID Principles

Single responsibility principle

Example

Choosing an axis

Open-closed principle

Example

Abstraction in JavaScript and TypeScript

Refactor earlier

Liskov substitution principle

Example

The constraints of substitution

Interface segregation principle

Example

Proper granularity

Dependency inversion principle

Example

Separating layers

Summary

9. The Road to Enterprise Application

Creating an application

Decision between SPA and "normal" web applications

Taking team collaboration into consideration

Building and testing projects

Static assets packaging with webpack

Introduction to webpack

Bundling JavaScript

Loading TypeScript

Splitting code

Loading other static assets

Adding TSLint to projects

Integrating webpack and tslint command with npm scripts

Version control

Git flow

Main branches

Supporting branches

Feature branches

Release branches

Hotfix branches

Summary of Git flow

Pull request based code review

Configuring branch permissions

Comments and modifications before merge

Testing before commits

Git hooks

Adding pre-commit hook automatically

Continuous integration

Connecting GitHub repository with Travis-CI

Deployment automation

Passive deployment based on Git server side hooks

Proactive deployment based on timers or notifications

Summary

3. Module 3

1. TypeScript 2.0 Fundamentals

What is TypeScript?

Quick example

Transpiling

Type checking

Learning modern JavaScript

let and const

Classes

Arrow functions

Function arguments

Array spread

Destructuring

Template strings

New classes

Type checking

Primitive types

Defining types

Undefined and null

Type annotations

Summary

2. A Weather Forecast Widget with Angular 2

Using modules

Setting up the project

Directory structure

Configuring TypeScript

Building the system

The HTML file

Creating the first component

The template

Testing

Interactions

One-way variable binding

Event listeners

Adding conditions to the template

Directives

The template tag

Modifying the about template

Using the component in other components

Showing a forecast

Using the API

Typing the API

Creating the forecast component

Templates

Downloading the forecast

Adding @Output

The main component

Using our other components

Two-way bindings

Listening to our event

Geolocation API

Component sources

Summary

3. Note-Taking App with a Server

Setting up the project structure

Directories

Configuring the build tool

Type definitions

Getting started with NodeJS

Asynchronous code

Callback approach for asynchronous code

Disadvantages of callbacks

The database

Wrapping functions in promises

Connecting to the database

Querying the database

Understanding the structural type system

Generics

Typing the API

Adding authentication

Implementing users in the database

Adding users to the database

Testing the API

Adding CRUD operations

Implementing the handlers

Request handling

Writing the client side

Creating the login form

Creating a menu

The note editor

The main component

Error handler

Running the application

Summary

4. Real-Time Chat

Setting up the project

Configuring gulp

Getting started with React

Creating a component with JSX

Adding props and state to a component

Creating the menu

Testing the application

Writing the server

Connections

Typing the API

Accepting connections

Storing recent messages

Handling a session

Implementing a chat message session

Connecting to the server

Automatic reconnecting

Sending a message to the server

Writing the event handler

Creating the chat room

Two-way bindings

Stateless functional components

Running the application

Comparing React and Angular

Templates and JSX

Libraries or frameworks

Summary

5. Native QR Scanner App

Getting started with NativeScript

Creating the project structure

Adding TypeScript

Creating a Hello World page

Creating the main view

Adding a details view

Scanning QR codes

Type definitions

Implementation

Testing on a device

Adding persistent storage

Styling the app

Comparing NativeScript to alternatives

Summary

6. Advanced Programming in TypeScript

Using type guards

Narrowing

Narrowing any

Combining type guards

More accurate type guards

Assignments

Checking null and undefined

Guard against null and undefined

The never type

Creating tagged union types

Comparing performance of algorithms

Big-Oh notation

Optimizing algorithms

Binary search

Built-in functions

Summary

7. Spreadsheet Applications with Functional Programming

Setting up the project

Functional programming

Calculating a factorial

Using data types for expressions

Creating data types

Traversing data types

Validating an expression

Calculating expressions

Parsing an expression

Creating core parsers

Running parsers in a sequence

Parsing a number

Order of operations

Defining the sheet

Calculating all fields

Using the Flux architecture

Defining the state

Creating the store and dispatcher

Creating actions

Adding a column or a row

Changing the title

Showing the input popup

Testing actions

Writing the view

Rendering the grid

Rendering a field

Showing the popup

Adding styles

Gluing everything together

Advantages of Flux

Going cross-platform

Summary

8. Pac Man in HTML5

Setting up the project

Using the HTML5 canvas

Saving and restoring the state

Designing the framework

Creating pictures

Wrapping other pictures

Creating events

Binding everything together

Drawing on the canvas

Adding utility functions

Creating the models

Using enums

Storing the level

Creating the default level

Creating the state

Drawing the view

Handling events

Working with key codes

Creating the time handler

Running the game

Adding a menu

Changing the model

Rendering the menu

Handling events

Modifying the time handler

Summary

9. Playing Tic-Tac-Toe against an AI

Creating the project structure

Configure TypeScript

Adding utility functions

Creating the models

Showing the grid

Creating operations on the grid

Creating the grid

Adding tests

Random testing

Implementing the AI using Minimax

Implementing Minimax in TypeScript

Optimizing the algorithm

Creating the interface

Handling interaction

Creating players

Testing the AI

Testing with a random player

Summary

10. Migrate JavaScript to TypeScript

Gradually migrating to TypeScript

Adding TypeScript

Configuring TypeScript

Configuring the build tool

Acquiring type definitions

Testing the project

Migrating each file

Converting to ES modules

Correcting types

Adding type guards and casts

Using modern syntax

Adding types

Refactoring the project

Enable strict checks

Summary

A. Bibliography

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部