Mastering JavaScript Promises
eBook - ePub

Mastering JavaScript Promises

Muzzamil Hussain

Compartir libro
  1. 188 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Mastering JavaScript Promises

Muzzamil Hussain

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Mastering JavaScript Promises un PDF/ePUB en línea?
Sí, puedes acceder a Mastering JavaScript Promises de Muzzamil Hussain en formato PDF o ePUB, así como a otros libros populares de Computer Science y Application Development. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2015
ISBN
9781783985500
Edición
1

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

Índice