Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Javascript Promises
Search
Felipe Bernardes
May 16, 2016
Programming
1
80
Javascript Promises
Lightning talk about Promises @ SorocabaJs
Felipe Bernardes
May 16, 2016
Tweet
Share
More Decks by Felipe Bernardes
See All by Felipe Bernardes
Gardening for Communities - Organically Cultivating Local Communities
felipebernardes
0
110
15 JavaScript Do's & Don'ts
felipebernardes
0
82
An Animated Poem, built with CSS drawings & animations
felipebernardes
1
120
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
70
Immersive Journalism using AR/VR
felipebernardes
0
140
7 Formas de Melhorar seu Networking
felipebernardes
0
35
BEM Show & Tell @ Space Coworking
felipebernardes
0
40
Get Started With PWAs
felipebernardes
0
95
CSS Layouting::putting things into place
felipebernardes
0
44
Other Decks in Programming
See All in Programming
マイクロサービスがほしいと思ったときに本当に必要だったもの〜なぜ人は共通基盤の夢を見るのか〜 / why microservice
77web
5
980
DocC Tutorial と TCA におけるテスト機能の紹介
kalupas226
1
330
オブジェクト指向は必要なのか / Is object-oriented needed?
kishida
27
19k
SwiftUI, Jetpack Composeの導入で変化した「家族アルバム みてね」のアプリ開発体験
hicka04
6
390
Enhancing Applications with Accessibility API
kishikawakatsumi
3
880
実践!RDRAを活用した既存システムの仕様変更 / Specification Changes in Existing Systems Utilizing RDRA
imamotohikaru
0
2.4k
「コンパイル時のユニットテスト」導入するとユニットテストを 書かなくてよくなるのか?
tomohisa
9
2.2k
Compiling Python to WebAssembly with py2wasm
syrusakbary
0
130
ONE WEDGE_Company_Information
1wedge
0
160
マイ隙間家具OSSたちのご紹介
karupanerura
2
150
Creating Retro-Style Photos Using Swift
ski
1
340
Laravel標準バリデーションでできること
hmb_ok
2
360
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
355
22k
Product Roadmaps are Hard
iamctodd
43
9.6k
We Have a Design System, Now What?
morganepeng
42
6.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
240
1.2M
What's in a price? How to price your products and services
michaelherold
236
11k
How STYLIGHT went responsive
nonsquared
92
4.7k
Agile that works and the tools we love
rasmusluckow
323
20k
Raft: Consensus for Rubyists
vanstee
130
6.2k
Embracing the Ebb and Flow
colly
78
4.1k
Fireside Chat
paigeccino
19
2.6k
From Idea to $5000 a Month in 5 Months
shpigford
376
45k
Ruby is Unlike a Banana
tanoku
95
10k
Transcript
promises && js2015 felipe bernardes github.com/felipebernardes
http://felipebernardes.github.io #votorantim http://tegra.me 2
None
execution stack && contexts
None
console.log(‘1’); setTimeout(() => console.log(‘2’), 0); console.log(‘3’); setTimeout(() => console.log(‘4’), 1000);
//1324
why promise?
None
• no more callback hell || pyramid of d00m ◦
better performance • cleaner && less code ◦ better to undestand ◦ easier to maintain ◦ responsabilities && modularization • better error handling
why not promise?
None
how to promise
doThis(param) .then( response => this.someAttr = param);
( ... ) //syncronous code doThis(param) .then( response => this.someAttr
= param); ( ... ) //syncronous code
doThis(param) .then( response => this.someAttr = param) .catch ( errorResponse
=> console.log(errorResponse) );
all && race
all http://jsfiddle.net/jsengel/mc3p01nb/ then after all promises returned, catch if any
of them fails
race then after one of the promises returns, catch if
any of them fails
var p3 = new Promise(function(resolve, reject) { setTimeout(resolve, 100, "three");
}); var p4 = new Promise(function(resolve, reject) { setTimeout(reject, 500, "four"); }); Promise.race([p3, p4]).then(function(value) { console.log(value); //three }
example
const setStatus = (group, status) => { const data =
{ status: status, shopId: group.shop.id, }; return $http.post(`${API}/group/${group.id}/shop/status`, data); }; // service
ShopListService.setStatus(this.group, 'closed') .then( () => this.group.shop.status = 'closed'); // controller
None
further reading
articles
html5rocks http://www.html5rocks.com/en/tutorials/es6/promises nomadev http://nomadev.com.br/angularjs-promises-promessas-o-guia- definitivo/ david walsh https://davidwalsh.name/write-javascript-promises
libs
$q https://github.com/kriskowal/q bluebird http://bluebirdjs.com/
python sorocaba - https://groups.google.com/forum/m/#!forum/python-sorocaba guru sorocaba - https://www.facebook.com/GURUSorocaba/ hacklab -
https://www.facebook.com/hacklabsorocaba/ GDG Sorocaba - https://www.facebook.com/GDGSorocaba/ SorocabaJS - https://www.facebook.com/sorocabajs/ JS Meetup - http://www.meetup.com/GDG-Sorocaba/ WomenTechmakers - https://www.facebook.com/groups/wtmsorocaba/ in.tegra.do - http://www.meetup.com/In-Tegra-Do/ english meetup - http://www.meetup.com/Sorocaba-English-Conversation-Happy-Hours/ #chegaMais
we're hiring
[email protected]
[email protected]
co-authored by felipe l. soares caique mitsuoka jean vitor
speakerdeck.com/felipebernardes valeu!