-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path2018_ng_arch_s.html
More file actions
949 lines (784 loc) · 28.2 KB
/
Copy path2018_ng_arch_s.html
File metadata and controls
949 lines (784 loc) · 28.2 KB
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Architecture with Angular</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<!--<link rel="stylesheet" href="reveal.js/css/theme/white.css" id="theme">-->
<!--<link rel="stylesheet" href="reveal.js/css/theme/black.css" id="theme">-->
<!--<link rel="stylesheet" href="reveal.js/css/theme/night.css" id="theme">-->
<!--<link rel="stylesheet" href="reveal.js/css/theme/simple.css" id="theme">-->
<link rel="stylesheet" href="reveal.js/css/theme/solarized.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<style>
/*pre code {*/
/*display: block;*/
/*padding: 0.5em;*/
/*background: #FFFFFF !important;*/
/*color: #000000 !important;*/
/*}*/
.right-img {
margin-left: 10px !important;
float: right;
height: 500px;
}
.weg:before {
content: 'Streichen?';
}
.weg {
color: red !important;
}
.presenter h1 {
color: rgb(255, 0, 234) !important;
}
.todo:before {
content: 'TODO: ';
}
.todo {
color: red !important;
}
code span.line-number {
color: lightcoral;
}
.reveal pre code {
max-height: 1000px !important;
}
img {
border: 0 !important;
box-shadow: 0 0 0 0 !important;
}
.reveal {
-ms-touch-action: auto !important;
touch-action: auto !important;
}
.reveal h2,
.reveal h3,
.reveal h4 {
letter-spacing: 2px;
font-family: 'Amiri', serif;
/* font-family: 'Times New Roman', Times, serif; */
font-weight: bold;
font-style: italic;
letter-spacing: -2px;
text-transform: none !important;
}
.reveal em {
font-weight: bold;
}
.reveal .step-subtitle h1 {
letter-spacing: 1px;
}
.reveal .step-subtitle h2,
.reveal .step-subtitle h3 {
text-transform: none;
font-weight: normal;
/* font-weight: 400; */
/* font-family: 'Amiri', serif; */
font-family: 'Lobster', serif;
letter-spacing: 1px;
color: #2aa198;
/* text-decoration: underline; */
}
.reveal .step-subtitle h3 {
text-decoration: underline;
font-style: normal
}
/* .reveal .step-subtitle h2 {
font-style: italic;
} */
.reveal .front-page h1,
.reveal .front-page h2 {
font-family: "League Gothic";
font-style: normal;
text-transform: uppercase !important;
letter-spacing: 1px;
}
.reveal .front-page h1 {
font-size: 2.5em !important;
}
.reveal .highlight {
/* #D3337B;*/
color: #268bd2;
}
.reveal section img {
background: none;
}
.reveal img.with-border {
border: 1px solid #586e75 !important;
box-shadow: 3px 3px 1px rgba(0, 0, 0, 0.15) !important;
}
.reveal li {
margin-bottom: 8px;
}
/* For li's that use FontAwesome icons as bullet-point */
.reveal ul.fa-ul li {
list-style-type: none;
}
</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) ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
<!--[if lt IE 9]>
<script src="reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section data-markdown class="preparation">
<textarea data-template>
### Preparation
* Start Data Server
* cd code\server
* yarn dev
* Start Angular Sample Apps
* For the basics
* cd code\ng\blueprint
* ng serve --port=4201
* http://localhost:4201/
* For Redux
* cd code\ng\ng-sandbox
* ng serve --port=4200
* http://localhost:4200/
</textarea>
</section>
<section>
<h2>Architecture with Angular</h2>
<div>
<a href="http://zeigermann.eu">Oliver Zeigermann</a> /
<a href="http://twitter.com/djcordhose">@DJCordhose</a> /
<a href="https://www.embarc.de/ ">embarc GmbH</a>
</div>
<p style="clear: both">
<small>Slides:
<a href="http://djcordhose.github.io/architecture/2018_ng_arch_s.html">
http://djcordhose.github.io/architecture/2018_ng_arch_s.html</a>
</small>
</p>
</section>
<section>
<h2>Wir nehmen Frontend-Architektur nicht für voll</h2>
<p>Zitate</p>
<ul>
<li class="fragment">
<em>Frontend-Architektur: Ich dachte sowas gibt es gar nicht</em>
</li>
<li class="fragment">
<em>Das Frontend kloppen wir am Ende einfach irgendwie drauf</em>
</li>
<li class="fragment">
<em>Architektur für ein bisschen CSS-Pixel-Geschubse?</em>
</li>
</ul>
</section>
<!-- <section data-markdown>
<textarea data-template>
### Konsistente UI ist gekoppelt
<img src='dan_soc.png'>
<small>
https://twitter.com/dan_abramov/status/1008131488481730561
</small>
</textarea>
</section> -->
<!-- <section data-markdown class="todo">
<textarea data-template>
### New React Context vs Redux
This a very comprehensive comparsion of two great tools, #ReactJS Context and #Redux with a nuanced and unobtrusive conclusion that is valid for almost all libX-vs-libY discussions. Thank you so much @dceddia for writing! 👍 https://t.co/tenlvKTOPQ
(https://twitter.com/nilshartmann/status/1021851945504591874?s=03)
</textarea>
</section>
<section data-markdown class="todo">
<textarea data-template>
### Do we need a framework, would Web Components do?
https://twitter.com/mislav/status/1022058279000842240
</textarea>
</section> -->
<!-- <section data-markdown class="todo">
<textarea data-template>
### React and TypeScript
* https://twitter.com/NaveenS16/status/1023433663873048577
* https://github.com/sw-yx/react-typescript-cheatsheet
</textarea>
</section> -->
<section>
<h2>Classic Web Applications</h2>
<img src="img/webapp-architecture-classic.png" style="max-width: 40%; float: left">
<ul style="max-width: 50%; float: right">
<li class="fragment" >Browser sends HTTP Request
<li class="fragment" >Content is <span class="highlight">rendered on the Server</span>
<li class="fragment" >HTML is sent back to the Browser
<li class="fragment" ><span class="highlight">Browser only shows the page</span> to the user
<li class="fragment" >Each interaction repeats this round-trip
</ul>
</section>
<section>
<h2>SPAs</h2>
<p>Move your Application to the Client</p>
<img src="img/webapp-architecture-spa.png" style="max-width: 40%; float: left">
<ul style="width: 50%; float: right; font-size: 80%">
<li class="fragment">only one (single) HTML page that mainly loads JavaScript and CSS</li>
<li class="fragment">Server has Data-API (JSON/REST API)</li>
<li class="fragment">Server can still hold Business Logic (or it is on the client only)
<li class="fragment">allows for Offline and best UX
</ul>
</section>
<section>
<img src="img/frontend-katz-twitter.png" height="600px">
<p><small><a href="https://twitter.com/wycats" target="_blank">
@wycats
</a>: <a href="https://twitter.com/wycats/status/930463710941872128" target="_blank">
https://twitter.com/wycats/status/930463710941872128
</a></small></p>
</section>
<section>
<img src="img/frontend-architecture.png" height="600px">
<p><small><a href="https://twitter.com/markdalgleish/status/908146609942257664" target="_blank">
https://twitter.com/markdalgleish/status/908146609942257664
</a></small></p>
</section>
<!-- <section>
<img src="img/kickme.png">
<p>
<small>
<a href="https://twitter.com/rhundhausen/status/932815147273474049" target="_blank">
https://twitter.com/rhundhausen/status/932815147273474049
</a>
</small>
</p>
</section> -->
<!-- <section>
<img src="img/light-elevator-twitter.png" height="600px">
<p><small><a href="https://twitter.com/ThePracticalDev/status/933373477255630853" target="_blank">
https://twitter.com/ThePracticalDev/status/933373477255630853
</a></small></p>
</section> -->
<!--
<section>
<img src="img/feynman-twitter.png">
<p><small><a href="https://twitter.com/ProfFeynman/status/932645521096716290" target="_blank">
https://twitter.com/ProfFeynman/status/932645521096716290
</a></small></p>
</section>
-->
<section data-markdown>
<textarea data-template>
### How to implement an SPA?
* https://stateofjs.com/
React is no. 1, Angular is still important, especially in the field of enterprise
</textarea>
</section>
<section>
<h3 style="line-height: 1em">Single-Page Applications</h3>
<h2>Components with Templates</h2>
<p style="color: #2aa198">A SPA is composed of (business) components:</p>
<ul class="fragment">
<li>Templates describe the UI of the component
<li>But now:
<ul>
<li>Logic is part of the component</li>
<li>Logic is a "first-class" citizen and no longer a "loose" snippet (like in jQuery)
<li><span class="highlight" >Logic is fully executed on the client</span></li>
</ul>
<li class="fragment">Prominent Frameworks: React, Angular, and Vue</li>
</ul>
</section>
<!-- <section data-markdown>
<textarea data-template>
### Creating a TypeScript based SPA with React
* npm install -g create-react-app
* create-react-app my-react-app --scripts-version=react-scripts-ts
* cd my-react-app
* yarn start
https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Creating an SPA with Angular 6
* https://nodejs.org
* https://yarnpkg.com
* https://github.com/angular/angular-cli
* npm install -g @angular/cli
</textarea>
</section> -->
<section data-markdown>
<textarea data-template>
### Creating an SPA with Angular 6
https://angular.io/guide/quickstart
* ng new blueprint
* cd blueprint
* ng serve
</textarea>
</section>
<section class="step-subtitle">
<h3>Composing an Application from Components</h3>
<h1>Smart and Dumb Components<span style="color:#D3337B">*</span></h1>
<h3 style='color:#586e75;font-family: "Amiri", serif;letter-spacing:-2px;text-decoration:none;font-weight:bold'><span style="color:#D3337B">*</span>also known as <em style='font-family: "League Gothic", Impact, sans-serif;letter-spacing:1px;font-style:normal;text-transform:uppercase'>Mediator Pattern</em> with Web Components / Polymer</h3>
</section>
<section>
<h3><span class="highlight">Smart</span> Components </h3>
<ul>
<li>Managing (part of) the application <span class="highlight">state</span>
<li>Contain UI <span class="highlight">logic</span></li>
<li>Pass parts of the state as immutable data to subcomponents</li>
<li>Pass callbacks to subcomponents for interaction</li>
<li>Mostly domain-specific, not intended to be reusable
</ul>
<p><em>Aka Container</em></p>
</section>
<section>
<h3><span class="highlight">Dumb</span> Components</h3>
<ul>
<li>only for <span class="highlight">presentation</span>, no logic
<ul>
<li>but might contain own ("transient") state
</li>
</ul>
<li>have <span class="highlight">no knowledge or dependencies</span> to their surrounding components
<li>children of Dumb Components are usually other Dumb Components
(but there are
<a target="_blank" href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.z8xy5zvhs">
exceptions</a>)
<li>reusable
</ul>
<p><em>Aka Presentational Component or just Component</em></p>
</section>
<section>
<img src="img/smart-dumb-properties.png">
</section>
<section>
<h2>Smart Component</h2>
<pre><code data-trim contenteditable class="javascript">
@Component({
template: `<sub [greeting]={{greeting}} (onSend)="sent($event)"></sub>`
})
export class AppComponent {
// component state
private greeting: string = 'Hiho';
// dependency injection
constructor(private greetingService: GreetingService) {
}
// "Business Logic" delegated to service
sent(greeting) {
this.greeting = this.greetingService.greetBack(greeting);
}
}
</code></pre>
<p><a target="_blank" href="https://angular.io/tutorial/toh-pt4">
https://angular.io/tutorial/toh-pt4</p>
</a></p>
</section>
<section>
<h2>Dumb Component</h2>
<pre><code data-trim contenteditable class="javascript">
@Component({
selector: 'sub',
template: `
<input [(ngModel)]="greeting">
<p>{{greeting}}, World</p>
<button (click)="send()">Send</button>
`,
})
export class SubComponent {
@Input() greeting: string;
// rxjs observer
@Output() onSend = new EventEmitter();
// no business logic, just event emitting
send() {
this.onSend.emit(this.greeting);
}
}
</code></pre>
</section>
<section>
<h3>Example</h3>
<img src="exercise/detail.png">
<p><small>What would be candidates for Smart-/Dumb-Components?</small></p>
</section>
<section>
<h3>Dumb</h3>
<img src="exercise/detail-dumb.jpg">
</section>
<section>
<h3>Smart</h3>
<img src="exercise/detail-smart.jpg">
</section>
<section data-markdown>
<textarea data-template>
### Many Leves of nesting Angular Components
* https://angular.io/guide/component-interaction
* https://stackoverflow.com/questions/43832941/angular-2-4-5-smart-dumb-and-deeply-nested-component-communication
* Custom Events do not bubble: https://stackoverflow.com/questions/42918423/angular-2-how-do-i-emit-an-event-up-through-multiple-nested-components
* https://angular.io/guide/template-syntax#remember-the-brackets
</textarea>
</section>
<section>
<h3>Code Sample: Intermediate Dumb Component</h3>
<pre><code data-trim contenteditable class="javascript">
@Component({
selector: 'app-container',
template: `<div class='contaner-layout'>
<app-title [titles]='titles'>
<h1>Hello!</h1>
</app-title>
<app-button (send)='send.emit()' title='Search'></app-button>
</div>`
})
export class Container {
@Input() titles;
@Output() send = new EventEmitter();
// optionally call this, if you need intermediate processing
// private buttonSend() {
// this.send.emit();
// }
}
</code></pre>
<p>Usage from Smart Component</p>
<pre><code data-trim contenteditable>
<app-container [titles]='titles' (send)='clicked()'></app-container>
</code></pre>
</section>
<section>
<h2>Title</h2>
<h3>Leaf Level Dumb Component</h3>
<pre><code data-trim contenteditable class="javascript">
@Component({
selector: 'app-title',
template: `<div class='title'>
<ng-content></ng-content>
<span *ngFor='let title of titles'>{{title.name}}</span>
</div>`
})
export class TitleComponent {
@Input() titles;
}
</code></pre>
</section>
<section>
<h2>Button</h2>
<h3>Button: Leaf Level Dumb Component</h3>
<pre><code data-trim contenteditable class="javascript">
@Component({
selector: 'app-button',
template: `<button (click)='send.emit()'>{{title}}</button>`
})
export class ButtonComponent {
@Input() private title = '';
@Output() send = new EventEmitter();
}
</code></pre>
</section>
<section class="next-step">
<h3>Smart and Dumb Components</h3>
<h2>Limitations</h2>
<p style="color: #2aa198">Mainly with growing and long-living applications</p>
<ul>
<li class="fragment" style="font-size: 80%">"God-like" components: State and logic tend to slowly move up to a few really fat components
<li class="fragment" style="font-size: 80%">Distributed, mutatable state makes maintainability and understanding hard
<ul>
<li>Where does the state belong to?</li>
<li>In which state is the application?
</ul>
</li>
<li class="fragment" style="font-size: 80%">Mash up of framework and UI code (hardens switching the framework)
<li class="fragment" style="font-size: 80%">Still open questions regarding the architecture
<ul>
<li>How to handle asynchronous code?
<li>How to do proper initialization of the application?
<li>How to test the business logic?
</ul>
</li>
</ul>
</section>
<section class="step-subtitle">
<h3>Statemanagement using a library</h3>
<h1>Redux as an Architectural Pattern</h1>
</section>
<section>
<h1>Redux</h1>
<ul>
<li><span class="highlight">Central</span> state management: one store for whole app, like a database</li>
<li><span class="highlight">External</span> state management: extract logic from the (UI-)components</li>
</ul>
<em>It's not only a framework, it's also a pattern (like MVC)</em>
</section>
<section>
<h2>Redux is independent of UI framework</h2>
<p style="color: #2aa198">Bindings exist for popular UI frameworks</p>
<ul style="font-size: 80%">
<li>React: <a href="http://redux.js.org/docs/basics/UsageWithReact.html" target="_blank">
http://redux.js.org/docs/basics/UsageWithReact.html
</a>
<li>Angular: <a href="https://github.com/ngrx/platform" target="_blank">https://github.com/ngrx/platform</a></li>
<a href="https://github.com/vuejs/vuex" target="_blank">https://github.com/vuejs/vuex</a>
<li>Web Components (Polymer): Redux is recommended implementation of <em>Global Mediator Pattern</em>,
<a href="https://twitter.com/DJCordhose/status/899943415353311232" target="_blank">https://twitter.com/DJCordhose/status/899943415353311232</a>
<a href="https://tur-nr.github.io/polymer-redux/" target="_blank">https://tur-nr.github.io/polymer-redux/</a>
</ul>
</section>
<section>
<h3>Redux extracts responsibility out of the UI framework</h3>
<img src="img/redux-02-extracting-responsibility.png" style="max-height: 500px; border:0;box-shadow:0 0 0 0"/>
</section>
<section>
<h3>Redux Pattern</h3>
<h2>Resulting Architecture</h2>
<img src="img/redux-03-resulting-redux-architecture.png" style="max-height: 500px; border:0;box-shadow:0 0 0 0"/>
</section>
<section data-markdown style="font-size: xx-large">
<textarea data-template>
### @ngrx/store
* yarn add @ngrx/store
* yarn add @ngrx/store-devtools
* yarn add @ngrx/effects
https://github.com/ngrx/platform/blob/master/docs/store/README.md
https://github.com/ngrx/platform/blob/master/docs/store-devtools/README.md
https://github.com/ngrx/platform/blob/master/docs/effects/README.md
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Demo
* Redux Tools
* Backend Calls
* Routing
* http://localhost:4200/root
* http://localhost:4200/counter
* Extract Parameters from URL: http://localhost:4200/counter/100
http://localhost:4200/
</textarea>
</section>
<!-- <section data-markdown style="font-size: xx-large">
<textarea data-template>
### Alternative for @ngrx/store
Why another state management framework for Angular?
* https://medium.com/@amcdnl/why-another-state-management-framework-for-angular-b4b4c19ef664
* http://ngxs.io/
</textarea>
</section>
-->
<section>
<h3>Reducer</h3>
<pre><code data-trim contenteditable class="javascript">
export function counterReducer(state: number = 0, action: Action) {
switch (action.type) {
case INCREMENT:
return state + 1;
case DECREMENT:
return state - 1;
case RESET:
return 0;
default:
return state;
}
}
</code></pre>
<pre><code data-trim contenteditable class="javascript">
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import { counterReducer } from './counter';
@NgModule({
imports: [StoreModule.forRoot({ count: counterReducer })],
})
export class AppModule {}
</code></pre>
</section>
<section>
<h3>Connection to Store</h3>
<pre><code data-trim contenteditable class="javascript">
interface AppState {
count: number;
}
@Component({
template: `<div>Current Count: {{ count$ | async }}</div>`
})
export class CounterComponent {
count$: Observable<number>;
constructor(private store: Store<AppState>) {
this.count$ = store.pipe(select('count'));
}
reset() {
this.store.dispatch({ type: RESET });
}
}
</code></pre>
</section>
<section>
<h2>Different Types of State</h2>
<img src="img/three-kinds-of-state.png">
</section>
<section>
<h3>@ngrx/effects</h3>
<pre><code data-trim contenteditable class="javascript">
@Injectable()
export class RemoteEffects {
constructor(private greetingService: GreetingService, private actions$: Actions) {}
@Effect()
login$: Observable<Action> = this.actions$.pipe(
ofType('LOAD'),
mergeMap(action => this.greetingService.requestGreeting('huhu').pipe(
// If successful, dispatch success action with result
map(data => ({ type: 'SET', payload: data.message.length })),
// If request fails, dispatch failed action
catchError(() => of({ type: 'FAILED'}))
))
);
}
</code></pre>
<pre><code data-trim contenteditable class="javascript">
import { EffectsModule } from '@ngrx/effects';
import { RemoteEffects } from './ngrx-sandbox/remote.effects';
@NgModule({
imports: [EffectsModule.forRoot([RemoteEffects])],
})
export class AppModule {}
</code></pre>
<small>
<a href='https://github.com/ngrx/platform/blob/master/docs/effects/README.md'>https://github.com/ngrx/platform/blob/master/docs/effects/README.md</a>
</small>
</textarea>
</section>
<section>
<h3>Is anyone really using this?</h3>
<div class="fragment">
<a href="https://www.xing.com/messenger" target="_blank">
<img src="xing-messenger-redux.png" height="550px">
</a>
<small>XING and many others use React and Redux</small>
</div>
</section>
<section>
<h2>Redux</h2>
<h3>Architectural guidance</h3>
<ul>
<li>Uni-directional data flow
<li>Central and immutable state: store
<li>Only reducers are allowed to modify state
<li>State moves from Smart Components to store
<li>UI logic moves from Smart Components in Action-Creators / Services and Reducer
<li>Asynchronous code only in Action-Creators / Services or Effects
<li>Initializing of the app with central action
</ul>
</section>
<section data-markdown>
<textarea data-template>
### But don't overdo it
<small>Spreading out your application into too many tiny fragments can make it hard to read and maintain</small>`
<img src='ngrx-overdone.jpg' height="500px">
<small>
https://twitter.com/jbandi/status/1023954402116358145
</small>
</textarea>
</section>
<!-- <section>
<h3>Wrap Up Redux</h3>
<p style="color: #2aa198">A UI pattern for User Interfaces</span>
<ul class="fragment" style="font-size:80%">
<li>Mainstream solution
<li>Independent of framework
<li>Easy testing of business logic as logic is implemented only in pure functions ("Reducer")
<li>Great debugging because of dev tools
<li>Works great in large applications with many dependencies between parts / components
</ul>
</section> -->
<section>
<h3>Wrap Up</h3>
<p style="color: #2aa198">Architectural Patterns for Angular Apps</span>
<ul>
<li class="fragment">Dependecy Injection
<li class="fragment">Services
<li class="fragment">Observables for everything
<li class="fragment">Composing your Application into Smart and Dumb Components
<li class="fragment">Redux
<ul>
<li>for large applications with many dependencies between parts / components
<li>provides architectural guidance where which part of the application goes
</ul>
</li>
</ul>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js "></script>
<script src="reveal.js/js/reveal.js "></script>
<script src="lib/jquery-2.2.4.js "></script>
<script>
// $('.weg').remove();
// uncomment for jax
$('.jax').remove();
if (window.location.hostname.indexOf('localhost') !== -1) {
} else {
// only applies to public version
$('.preparation').remove();
$('.todo').remove();
$('.local').remove();
$('.presenter').remove();
}
Reveal.addEventListener('ready', function (event) {
if (window.location.hostname.indexOf('localhost') !== -1) {
// only applies to presentation version
Reveal.configure({ controls: false });
} else {
// only applies to public version
$('.fragment').removeClass('fragment');
}
// applies to all versions
$('code').addClass('line-numbers');
});
// $('section').attr('data-background-image', "backgrounds/light-metal.jpg ");
// $('section').attr('data-background-image', "backgrounds/pink.jpg ");
$('section').attr('data-background-image', "backgrounds/white.jpg ");
// $('section').attr('data-background-image', "backgrounds/code.jpg ");
</script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
width: 1100,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{
src: 'reveal.js/lib/js/classList.js', condition: function () {
return !document.body.classList;
}
},
{
src: 'reveal.js/plugin/markdown/marked.js', condition: function () {
return !!document.querySelector('[data-markdown]');
}
},
{
src: 'reveal.js/plugin/markdown/markdown.js', condition: function () {
return !!document.querySelector('[data-markdown]');
}
},
{
src: 'reveal.js/plugin/highlight/highlight.js', async: true, condition: function () {
return !!document.querySelector('pre code');
}, callback: function () {
hljs.initHighlightingOnLoad();
}
},
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: 'reveal.js/plugin/notes/notes.js', async: true },
{ src: 'lib/js/line-numbers.js' }
]
});
</script>
</body>
</html>