万本电子书0元读

万本电子书0元读

顶部广告

Mastering JavaScript Promises电子书

售       价:¥

0人正在读 | 0人评论 9.8

作       者:Muzzamil Hussain

出  版  社:Packt Publishing

出版时间:2015-07-24

字       数:76.7万

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

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

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
This book is for all the software and web engineers wanting to apply the promises paradigm to their next project and get the best outcome from it. This book also acts as a reference for the engineers who are already using promises in their projects and want to improve their current knowledge to reach the next level. To get the most benefit from this book, you should know basic programming concepts, have a familiarity with JavaScript, and a good understanding of HTML.
目录展开

Mastering JavaScript Promises

Table of Contents

Mastering JavaScript Promises

Credits

About the Author

About the Reviewers

www.PacktPub.com

Support files, eBooks, discount offers, and more

Why subscribe?

Free access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Promises.js

The fall and rise of JavaScript

Google's contributions to JavaScript

Where Promises.js came in?

What is a promise?

Why do we need promise in JS?

Software prerequisites

Environment you need before getting started

Future, promise, and delay

Promise pipelining

Read-only views

States of a promise

How do we keep Promises.js in this book?

Browser compatibility

Summary

2. The JavaScript Asynchronous Model

Programming models

The single-threaded synchronous model

The multithreaded synchronous model

The asynchronous programming model

Densities with an asynchronous programming model

Why do we need to block the task?

Why not use some more threads?

Learning the JavaScript asynchronous model

How JavaScript implements an asynchronous model

Callbacks in JavaScript

Blocking functions

The mechanism of a callback function in JavaScript

Basic rules to implement callbacks

Handling callback hell

The events

The mechanism of event handling

DOM – event capture and event bubbling

A list of the most common events handlers

Triggering functions in response to events

Types of events in JavaScript

Interface events

Mouse events

Form events

W3C events

Microsoft events

Mozilla events

The publisher/subscriber

A brief account of the observer pattern

A formal definition of observer

The push and pull model

The advent of observer/push-pub

The drawbacks of observer/push-pub

The promises object

Summing up – the asynchronous programing model

Summary

3. The Promise Paradigm

Callback, revisited

Promise

Deferred

How do promise and deferred relate to each other?

Standard behaviors of the Promise API

Interactive promises

The states and return values of a promise

Common sequencing patterns

Stacked

Parallel

Sequential

Decoupling events and applications logic

Promises as event emitters

What promises prescribed not to do

Avoiding getting into callback hell

Avoiding the use of unnamed promises

Promises and exceptions

The fail method

The then method

Best practices to handle exceptions in promise

Make your exceptions meaningful

Monitor, anticipate, and handle exception

Keep it clean

Considerations while choosing a promise

Summary

4. Implementing Promises

How to implement promises

Implementations in Java

The util package of Java

The mechanics of Java to implement a promise

The core components of java.util.concurrent

Executor

Queues

Timing

Synchronizers

Concurrent collections

The implementation of promise by Java

CompletionService

ExecutorService

Future

Delay and DelayedQueue

FutureTask

Summing up Java and Promises.js

Say hello to JDeferred

A few words about Android Deferred Object

Use case 1 – object success and failure callbacks for a task

Use case 2 – merging several promises

Mechanics of JDeferred

Features of JDeferred

Playing with the code using JDeferred

Deferred object and promise

Deferred Manager

Runnable and callable

wait() and waitSafely()

Filters

Pipes

Ultimate JDeferred

Summary

5. Promises in WinRT

An introduction to WinRT

The evolution of WinRT

A little detail about WinJS

WinJS – its purpose and a distribution history

WinJS on GitHub

HTML5, CSS3, and JavaScript

WT with HTML5, CSS3, and JavaScript

The need for integrating promise with WT

Problems when using asynchronous programming

Jumpstarting promises

Writing a function that returns a promise

Adding a change handler for input elements

Error handling

Chaining promises using the then() and done() functions

Example 1A – downloading a web page to a file using two asynchronous functions

Example 1B – downloading a web page to a file using startAsync

Summary

6. Promises in Node.js

The V8 engine – the mechanics

The V8 engine in Google Chrome

The evolution of Node.js

A brief introduction to Node.js

Download and install Node.js

Node Package Manager – NPM

Choice of environment

Setting up the environment for Node.js

A simple node server

Things we learned so far

Node.js with the Q library

Moving ahead with Q

Propagation in Q

Chaining and nesting promises

Sequences in Q

Combination in Q

How to handle errors in Q in Node.js

Making progress with promises

Getting to the end of a chain of promises

Callback-based promises versus Q-based promises

A few words on delay, timeout, and notify

Q.delay()

Q.timeout()

deferred.notify()

Q.Promise() – another way to create promises

Static methods of Q

Promise as a proxy

Familiarizing Node.js – the Q way

Unbinds and its solution

Q support for tracing stacks

Making promise-based actions

Object handling promises

Decomposition of primitive access

View revisited

Aborting a promise

Q utilities for Node.js

Summary

7. Promises in Angular.js

The evolution of Angular.js

The structure of the Angular.js document

Getting started with Angular.js

Creating your first Angular.js file

Step 1 – create the HTML 5 doc

Step 2 – add the JavaScript file to it

How to use Angular.js on your local machine

What would be your preference for the server?

Key elements of Angular.js

Supplying scope data

Filtering data

Controlling scopes

Routing views

Implementing promises in Angular.js

The schematics of using promises in Angular.js

Promise as a handle for callback

Blindly passing arguments and nested promises

Deferred objects or composed promises

Dealing with the nested calls

Concurrency in Angular.js

The combination of success and error

The safe approach

Route your promise

Summary

8. Promises in jQuery

From where it started?

Behind the scenes – how does jQuery work?

Is your document ready to submit?

How to use jQuery

The syntax

Caching in jQuery

A sample example

Selectors

Event methods

JavaScript before and after jQuery

The solution – introducing promises in jQuery

Deferred in jQuery

$.Deferred().promise() in jQuery

Projecting a promise in jQuery

Joining promises with $.when

Your own $.Deferred process

The advent of promises in jQuery

Summary

9. JavaScript – The Future Is Now

ECMAScript 6 (ECMA 262)

harmony:generators

The Fibonacci series

The MEAN stack

Real-time communication in JavaScript

Internet of Things

Computer animation and in 3D graphics

NoSQL databases

Summary

Index

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

发表评论

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

买过这本书的人还买过

读了这本书的人还在读

回顶部