forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
366 lines (336 loc) · 9.24 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>reveal.js</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<style>
.reveal pre {
width: 100%;
}
.reveal pre code {
max-height: 420px;
}
</style>
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-markdown>
# What's new? ES6 features for Node v6.9.5
</section>
<section>
<section data-markdown>
## let & const
(from Node v4)
</section>
<section data-markdown>
What is hoisting?
```
x = 5; // assign 5 to x
var x; // declare x
console.log(x); => 5
```
Javascript hoists (↑) function and variable declarations
</section>
<section data-markdown>
using let...
```
x = 5; // ReferenceError: x is not defined
let x;
console.log(x);
```
</section>
<section data-markdown>
another example using var
```
const functions = [];
for(var i = 0; i < 5; i++) {
functions.push(() => i);
}
console.log(functions[3]()); => 5
```
</section>
<section data-markdown>
instead use let
```
const functions = [];
for(let i = 0; i < 5; i++) {
functions.push(() => i);
}
console.log(functions[3]()); => 3
```
</section>
<section data-markdown>
const
```
const a = 1;
a = 2; // TypeError: Assignment to constant variable
```
```
const a = {};
a.b = 2;
console.log(a); // { b: 2 }
```
```
const a = [1];
a[0] = 2;
console.log(a); // [2]
```
</section>
</section>
<section>
<section data-markdown>
## arrow functions
(from Node v4)
</section>
<section data-markdown>
```
function sum(a, b) {
return a + b;
}
// using arrow fn
const sum = (a, b) => {
return a + b;
};
// composing functions
const sum2 = (a) => (b) => {return a+b;}
console.log(sum2(1)(2)); // => 3
```
</section>
<section data-markdown>
models/accounts.js
```
function getFixedCurrenciesArray(currencies, masterCurrencies){
var result =[];
for (var i = 0; i < currencies.length; i++){
var currency = currencies[i];
var masterCurrency = _.find(masterCurrencies, function(mc) {
return mc.isocode === currency;
});
if (masterCurrency){
result.push(masterCurrency);
}
}
return result;
}
```
</section>
<section data-markdown>
models/accounts.js
```
// refactored using arrow functions
function getFixedCurrenciesArray(currencies, masterCurrencies) {
// super simple to define curryfied functions
// to improve our code :D
const sameIsoCode = (mc) => (c) => c === mc.isocode;
return masterCurrencies.filter((mc) => {
return currencies.find(sameIsoCode(mc));
});
}
```
</section>
</section>
<section>
<section data-markdown>
## default parameters
(from Node v6.0.0)
</section>
<section data-markdown>
route_definitions.js
```
function getIncompleteTrip(schedule, options, stations,
trip, dontApplyCutoff) {
// ...
if (!dontApplyCutoff) {
hhMM = cutOffService.isAfterCutOff(schedule, options);
}
// client code:
getIncompleteTrip(schedule, data, stations, trip, false);
```
</section>
<section data-markdown>
route_definitions.js
```
// refactoring :D
function getIncompleteTrip(schedule, data, stations,
trip, applyCutoff = false) {
// ...
if (applyCutoff) {
hhMM = cutOffService.isAfterCutOff(schedule, data);
}
// client code:
getIncompleteTrip(schedule, data, stations, trip);
```
</section>
</section>
<section>
<section data-markdown>
## destructuring
(from Node v6.0.0)
</section>
<section data-markdown>
pattern matching
```
let [a, , b] = [1,2,3];
// a = 1
// b = 3
const user = {name: "Jim", lastname: "Morrison", age: 27};
const {name} = user;
// name = "Jim"
```
fail-soft
```
let [a] = [];
// a = undefined
```
</section>
<section data-markdown>
route_definitions.js
```
// refactoring :D
function getIncompleteTrip(schedule, data, stations,
trip, {applyCutoff = false} = {}) {
// ...
if (applyCutoff) {
hhMM = cutOffService.isAfterCutOff(schedule, data);
}
// client code:
getIncompleteTrip(schedule, data, stations, trip,
{applyCutoff: true});
```
</section>
</section>
<section>
<section data-markdown>
## rest & spread
(from Node v6.0.0)
</section>
<section data-markdown>
### rest
```
function f(x, ...y) {
// y is an Array
return x * y.length;
}
f(3, "hello", true); // => 6
```
### spread
```
function f(x, y, z) {
return x + y + z;
}
// Pass each elem of array as argument
f(...[1,2,3]); // => 6
```
</section>
<section data-markdown>
the betterez-app async helper is an example using the rest and spread operators
```
function expectAsync(done, expectedFn) {
return function(...args) { // rest
try {
expectedFn(...args); // spread
done();
} catch (err) {
done(err);
}
};
}
```
</section>
</section>
<section data-markdown>
## What's comming up for us?
</section>
<section>
<section data-markdown>
## async functions
(from Node v7.6.0)
</section>
<section data-markdown>
### async/await
* A new way to write asynchronous code
* It's actually built on top of promises
* Like promises, non blocking
* Makes asynchronous code look and behave a little more like synchronous code
</section>
<section data-markdown>
Using promises (connex-trips-data-service.js from btrz-api-inventory)
```
filterTripData(trips, options, _currentDate_) {
// ...
return this.searchFilters.filterOffByDate(trips, options, _currentDate_)
.then((result) => {
return this.searchFilters.filterOffByCapacity(result, options);
})
.then((result) => {
return this.searchFilters.filterOffByHoliday(result, options.dateConfiguration);
})
.then((result) => {
return this.setTripsPrice(options.accountId, options.productId, result);
})
.then((result) => {
if (options.pricingType === "distance") {
return this.distanceBucketsDataService.get({accountId: options.accountId, productIds: {$in: [options.productId]} })
.then((distanceBuckets) => {
return this.searchFilters.filterOffByDistance(result, distanceBuckets);
});
}
return result;
})
.then((result) => {
return SearchFilters.cleanTrips(result);
});
}
```
</section>
<section data-markdown>
Refactoring async/await
```
async filterTripData(trips, options, _currentDate_) {
// ...
let result = await this.searchFilters.filterOffByDate(trips, options, _currentDate_);
result = await this.searchFilters.filterOffByCapacity(result, options);
result = await this.searchFilters.filterOffByHoliday(result, options.dateConfiguration);
result = await this.setTripsPrice(options.accountId, options.productId, result);
if (options.pricingType === "distance") {
const distanceBuckets = await this.distanceBucketsDataService.get({accountId: options.accountId, productIds: {$in: [options.productId]} });
result = this.searchFilters.filterOffByDistance(result, distanceBuckets);
}
return SearchFilters.cleanTrips(result);
}
```
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
history: true,
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>