-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslides.html
399 lines (266 loc) · 6.95 KB
/
slides.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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=PT+Sans:400,400italic);
@import url(https://cdn.jsdelivr.net/font-hack/2.020/css/hack.min.css);
body {
font-family: 'PT Sans';
}
.remark-slide-content{
background: #5C5352;
}
h1, h2, h3 {
font-family: 'PT Sans';
font-weight: lighter;
}
.remark-code, .remark-inline-code { font-family: 'Hack'; }
.inverse {
background: #0C2342;
color: #2590C3;
}
</style>
</head>
<body>
<textarea id="source">
class: center, middle, inverse
# Lessons Learned Making an Open-Source Plugin Framework
### a.k.a. How to Modernize Your JS for Much Success
---
class: center, middle, inverse
# What Framework?

???
What is XSplit?
What is a plugin?
---
class: center, middle


???
What is this framework? we're not talking about a jQuery plugin
How did we make the plugin framework?
---
class: center, middle, inverse
# Lesson 1: Don't be scared of new things
???
TypeScript: support for type checking, for next-generation JS
built everything from scratch
bleeding-edge has pros and cons, sometimes you should take the plunge
---
class: middle
```typescript
export class File implements Addable {
private _path: string;
addToScene(): Promise<boolean> {
return new Promise(resolve => {
iApp.callFunc('addfile', this._path).then(() => {
resolve(true);
});
});
}
}
```
---
class: center, middle, inverse
# Lesson 2: Be willing to accept changes in code
???
concept of code ownership can go too far
went through at least 3 iterations
refactor refactor refactor!
effect on user feedback?
---
class: center, middle, inverse
# Lesson 3: Committed to nonbreaking changes
???
emphasize that this is to be used not internally, but by other people
after version 1, ensure compatibility, non changing API
console.warn is a good thing
talk about semver. minor versions should simply deprecate, never break
---
class: center, middle, inverse
# Lesson 4: Always document your code
---
class: middle
```typescript
/**
* return: Promise<Scene>
*
* Get a specific scene object given the scene number.
*
*
* #### Usage
*
* ```javascript
* var scene1;
* Scene.getByIdAsync(1).then(function(scene) {
* scene1 = scene;
* });
* ```
*/
static getByIdAsync(sceneNum: number): Promise<Scene> {
return new Promise(resolve => {
Scene._initializeScenePoolAsync().then(cnt => {
resolve(Scene._scenePool[sceneNum - 1]);
});
});
}
```
???
descriptive docs, generated by dgeni
sample code
do not break encapsulation in your docs. users do not need to know all the little details
docs are also reflected in error messages
docs also contain recommended patterns in using framework
release notes!
---
class: center, middle, inverse
# Lesson 5: Make sure your code is tested
???
we test with Jasmine
continuous integration with Travis
useful when doing large refactoring
Travis build passed badge ;)
---
class: center



---
class: center, middle, inverse
# Lesson 6: Automate repetitive tasks
???
things we automate: building (includes transpiling, bundling, minification), docgen, tests, version appending
things we want to automate: linting
---
class: middle
```javascript
gulp.task('browserify', function() {
return browserify('./src/index.ts')
.plugin('tsify', {
target: 'ES5',
declaration: true })
.require('./src/index.ts', {expose: 'xjs'})
.bundle()
.pipe(source('xjs.js'))
.pipe(gulp.dest('dist'));
});
```
???
how we did it: gulp
how to do it now? grunt, npm scripts are also options
webpack building -> webpack 2 includes tree shaking
---
class: center, middle, inverse
# Lesson 7: Modernize your JavaScript for much success
---
class: middle
### Promises
```javascript
var xjs = require('xjs');
xjs.ready().then(xjs.Source.getCurrentSource)
.then(function(source){
return source.getSceneId();
}).then(function(id){
return xjs.Scene.getById(id)
}).then(function(scene){
return scene.getSources();
}).then(function(items){
var p;
for (var i in items) {
items[i].getName().then(function(name) {
p = document.createElement('p');
p.textContent = name;
document.body.appendChild(p);
});
}
});
```
???
Promises to avoid callback hell
---
class: middle
### Classes
```typescript
export class CameraDevice implements Addable {
private _id: string;
private _name: string;
constructor(props?: {}) {
this._id = props['id'];
this._name = props['name'];
}
```
???
TypeScript: use ES2015 features
JS Classes
---
class: middle
`version.ts`
```javascript
export function getVersion(): string {
let xbcPattern = /XSplit Broadcaster\s(.*?)\s?/;
let xbcMatch = navigator.appVersion.match(xbcPattern);
if (xbcMatch !== null) {
return xbcMatch[1];
} else {
throw new Error('not loaded in XSplit Broadcaster');
}
}
```
`item.ts`
```typescript
import {IItemLayout} from './ilayout'
import {minVersion, versionCompare, getVersion} from 'util/version'
export class Item implements IItemLayout {
getSourceId(): Promise<string> {
return new Promise((resolve, reject) => {
if (versionCompare(getVersion()).is.lessThan(minVersion)) {
// ...
}
})
}
}
```
???
Module system to have easier code structure
---
class: center, middle, inverse
# Lesson 8: Learn from established patterns
---
class: middle
```javascript
var button = document.getElementById('openDialogButton');
button.addEventListener('click', function() {
xjs.Dialog.createDialog('your.url/here.html')
.setSize(500, 800)
.setTitle('ThisDialogReturnsAString')
.setBorderOptions(true, false)
.setButtons(true, true)
.show()
.getResult().then(function(result) {
document.getElementById('input').value = result;
});
});
```
???
(in addition to making use of established libraries instead of reinventing the wheel)
Learn techniques from libraries and frameworks in the wild
Beautiful interface with a fluent interface with our method chaining: examples are with setting properties, or initializing a NewDialog
Beautiful code with coding standards. In addition to linting, use your text editor (.editorrc, Sublime margins + whitespace display settings)
suggest airbnb
---
class: center, middle, inverse
# Lesson 9: Have a vision for your project
???
Makes for a consistent API
Github issues might have unusual requests, make sure to know how to approach them
</textarea>
<script src="https://gnab.github.io/remark/downloads/remark-latest.min.js">
</script>
<script>
var slideshow = remark.create();
</script>
</body>
</html>