Mastering JavaScript Promises
eBook - ePub

Mastering JavaScript Promises

Muzzamil Hussain

Buch teilen
  1. 188 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Mastering JavaScript Promises

Muzzamil Hussain

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Mastering JavaScript Promises als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Mastering JavaScript Promises von Muzzamil Hussain im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Application Development. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2015
ISBN
9781783985500

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 Thing...

Inhaltsverzeichnis