Slide 1

Slide 1 text

Angular Core Abstractions The Iterable Differs eliraneliassy

Slide 2

Slide 2 text

e-square.io — Founder & CEO @ e-square.io — Angular Google Developer Expert — Writer @ AngularInDepth — Community leader About mySelf

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Angular EXPERTS on demand https://e-square.io info@e-square.io Want to join us? jobs@e-square.io

Slide 5

Slide 5 text

e-square.io New Angular Conference… Coming soon…

Slide 6

Slide 6 text

e-square.io Let’s Start!

Slide 7

Slide 7 text

e-square.io Angular CD • Asynchronous events • Input/Ouput • User DOM interactions Angular will check if any of the bindings has changed Teardown -> repaint the component

Slide 8

Slide 8 text

Angular CD

Slide 9

Slide 9 text

Event! Angular CD

Slide 10

Slide 10 text

Event! Angular CD

Slide 11

Slide 11 text

CD CD CD CD CD CD CD Angular CD

Slide 12

Slide 12 text

onPush Event! Angular CD

Slide 13

Slide 13 text

CD onPush CD CD CD Angular CD

Slide 14

Slide 14 text

e-square.io onPush is enough? • NO. • Repainting is expensive(!!) • onPush is an important optimization - but, itself is probably not enough to even for small applications • Why? ngFor, ngStyle, ngClass - highly in use by Angular developers

Slide 15

Slide 15 text

e-square.io Introducing IterableDiffers • Angular core abstraction • provider that allow us to compare two collections and produce a list of changes in the form of “IterableChanges” collection • Changes? Added Items, removed Items, changed position Items etc.

Slide 16

Slide 16 text

e-square.io IterableDiffers

Slide 17

Slide 17 text

e-square.io IterableDiffers Find

Slide 18

Slide 18 text

e-square.io IterableDiffers Create

Slide 19

Slide 19 text

e-square.io IterableDiffers Extend

Slide 20

Slide 20 text

e-square.io IterableDiffer Types • Default Iterable Differ • Default Key Value Differ • Key Value Differ

Slide 21

Slide 21 text

e-square.io Live coding…

Slide 22

Slide 22 text

e-square.io Track changes in array

Slide 23

Slide 23 text

e-square.io Track changes in array

Slide 24

Slide 24 text

e-square.io Track changes in array

Slide 25

Slide 25 text

e-square.io Track changes in array

Slide 26

Slide 26 text

e-square.io Track changes in Objects

Slide 27

Slide 27 text

e-square.io Track changes in Objects

Slide 28

Slide 28 text

e-square.io Track changes in Objects

Slide 29

Slide 29 text

e-square.io Track changes in Objects

Slide 30

Slide 30 text

e-square.io Track changes in Objects

Slide 31

Slide 31 text

e-square.io Add trackby function

Slide 32

Slide 32 text

e-square.io Add trackby function

Slide 33

Slide 33 text

e-square.io Add trackby function

Slide 34

Slide 34 text

e-square.io DIY - ngStyle

Slide 35

Slide 35 text

e-square.io DIY - ngStyle

Slide 36

Slide 36 text

e-square.io DIY - ngStyle

Slide 37

Slide 37 text

e-square.io DIY - ngStyle

Slide 38

Slide 38 text

e-square.io DIY - ngStyle

Slide 39

Slide 39 text

e-square.io Practical Example - Filters

Slide 40

Slide 40 text

e-square.io Improving ngFor Super Fast Differs! • ngFor - Arrays, Objects • IterableDiffer can find whether given collection has changed by checking the whole collection ≈ O(n) • But, what if we’ll move the “what has been changed” logic to the collection itself? ≈ O(1) • Inspired by Minko Gechev blog: https://mgv.io/ng-diff

Slide 41

Slide 41 text

e-square.io ngFor

Slide 42

Slide 42 text

e-square.io The DifferableList

Slide 43

Slide 43 text

e-square.io The DifferableList

Slide 44

Slide 44 text

e-square.io The DifferableList Iterator

Slide 45

Slide 45 text

e-square.io The DifferableList Differ

Slide 46

Slide 46 text

e-square.io The DifferableList Factory

Slide 47

Slide 47 text

e-square.io Extend the IterableDiffers

Slide 48

Slide 48 text

e-square.io what we have learned • What are IterableDiffers and how Angular use them to accelerate our applications performance • How we can create our custom IterableDiffer and extend the IterableDiffers by using CS technics

Slide 49

Slide 49 text

e-square.io Special Thanks

Slide 50

Slide 50 text

Keep in Touch with me! https://e-square.io https://eliassy.dev @eliraneliassy eliran@e-square.io

Slide 51

Slide 51 text

Thank You