×
What you cannot expect
@MartinaKraus11
What you can expect
GDE in Angular
Women Techmakers Ambassador
Trainer and Consultant
@MartinaKraus11
Martina Kraus
martinakraus
@MartinaKraus11
@MartinaKraus11
13:30 - 15:00
15:30 - 16:45
15:00 - 15:30
Part 1: Ivy as an enabler
Coffee break
Part 2: Libraries with Ivy
@MartinaKraus11
Node.js
Angular.CLI (Angular >= 8.x)
Google Chrome
Code Editor
@MartinaKraus11
Example Repo and exercises:
http://bit.ly/angular-days-ivy
Slides:
http://bit.ly/slides-mk-ivy
@MartinaKraus11
Better build times, thanks to incremental compilation
Smaller and faster bundles
Sets the ground for lazy-loading components
Is easy to debug
Introduces new non-zone.js based change detection
Uses higher-order components
@MartinaKraus11
tsconfig.json
//to Opt-out:
"angularCompilerOptions": {
"enableIvy": false
}
@MartinaKraus11
Angular
declarative Code
ngc
JavaScript Code
@MartinaKraus11
ngc
@Component({ selector: ‘app-component’ template: `<h1>{{ title }}</h1>` }) export class AppCmp {}
JavaScript Code
@MartinaKraus11
export class AppCmp { title: string; ngComponentDef = ng.defineComponent( {...}) }
ngc
@Component({ selector: ‘app-component’ template: `<h1>{{ title }}</h1>` }) export class AppCmp {}
@MartinaKraus11
Scoping (ngModules)
Evaluation of
Property chains
Variables / function calls
Type checking
@MartinaKraus11
Smaller
Faster Compilation
Easier to debug
Ivy as enabler
@MartinaKraus11
Smaller
Faster Compilation
Easier to debug
Ivy as enabler
@MartinaKraus11
@MartinaKraus11
> ng new awesome-app
> ngc
@MartinaKraus11
// 11.2.4
> ng new awesome-app
> ngc
ViewEngine:
1,4MB
Ivy:
14kB
DEMO
@MartinaKraus11
app.cmp.ts
app.cmp.html
app.cmp.scss
app.cmp.js
app.cmp.ngFactory.js
app.cmp.metadata.json
app.cmp.ngsummary.json
@MartinaKraus11
app.cmp.ts
app.cmp.html
app.cmp.scss
app.cmp.js
@MartinaKraus11
Tree shaking is a term commonly used for dead-code elimination in the JavaScript Context.
It relies on the static structure of module syntax.
Takes place during the compilation of the Angular app
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
HTML Template
Data
Template
Angular Interpreter
DOM
@MartinaKraus11
export function elementStart()
export function text()
Ivy instructions
Unsused Code
export function pipe()
@MartinaKraus11
HTML Template
Template instructions
DOM
@MartinaKraus11
Angular-Apps
Others
Delta.com: 4.2MB
Forbes.com: 5.7MB
Android Messages: 1.1MB
Grubhub: 3.4MB
microsoft.com is 1.4MB
amazon.com is 7.5MB
Wikipedia pages are 223KB
reddit.com is 4.9MB
netflix.com is 4.2MB
twitter.com is 3.5MB
Stephen Fluin - https://fluin.io/blog/is-my-angular-performance-normal
@MartinaKraus11
angular.json
@MartinaKraus11
Smaller
Faster Compilation
Easier to debug
Ivy as enabler
@MartinaKraus11
static ɵcmp = core.ɵɵdefineComponent({…})
app.component.js
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
Component has all information for being compiled
No global compilation anymore
Ivy provides stable API to ship code through npm
Modules already AOT
@MartinaKraus11
Smaller
Faster Compilation
Easier to debug
Ivy as enabler
@MartinaKraus11
Ivy runtime offers a new ng object for debugging Angular apps, when you run in Dev mode.
This ng object can be accessed in the Developer console of Google Chrome
Offers different Entry Points to access and modify a component and its dependencies
DEMO
@MartinaKraus11
@MartinaKraus11
Smaller
Faster Compilation
Easier to debug
Ivy as enabler
@MartinaKraus11
Lazy loading components
Higher Order Components
Zoneless
change detection
@MartinaKraus11
@MartinaKraus11
ComponentFactoryResolver
@MartinaKraus11
ViewContainerRef
Injector
@MartinaKraus11
@MartinaKraus11
Lazy loading components
Higher Order Components
Zoneless
change detection
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
DEMO
@MartinaKraus11
Modifying component traits at runtime
(Automatically unsubscribing/ subscribing, changing styles)
More dynamic
Every Ivy component is a standalone component
@MartinaKraus11
Lazy loading components
Higher Order Components
Zoneless
change detection
@MartinaKraus11
Hard dependency of every Angular Application
"zone.js": "~0.10.2"
NgZone triggers the change detection automatically
Takes care of all event handlers and data bindings
@MartinaKraus11
More than 100kB
many performance issues
(long cd cycles together with frequent browser events)
too much magic
@MartinaKraus11
Ivy has been defined without considering Zone.js
@MartinaKraus11
Calling Angular to check data Binding with Ivy Instruction
@MartinaKraus11
Angular Libraries with Ivy
@MartinaKraus11
@MartinaKraus11
The Code that will be compiled with Ivy uses the ngtsc compiler
Libraries, npm modules, other dependencies are already precompiled
@MartinaKraus11
ngcc scans node_modules and produces Ivy-compatible versions of each package
detects the Angular Package Format (APF) and searches
for .metadata.json file and the package's entrypoint
creates output directory ngcc_node_modules (default)
@MartinaKraus11
@MartinaKraus11
copied
copied
converted
@MartinaKraus11
@MartinaKraus11
producing a partial class using JS AST
extract the static property definition from the partial class
@MartinaKraus11
Using Libraries
Lib author
@MartinaKraus11
#1: Error: Failed to compile entry-point <packagename> due to compilation errors: node_modules/<packagename>/bundles/filename.umd.js(1034,34)]
The issue:
ngcc wasn't able to find a proper entrypoint for converting instructions nor able to create wrapper files
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
Libraries can be compiled ahead-of-time and be published as such to NPM, GitHub Packages etc.
@MartinaKraus11
@MartinaKraus11
@MartinaKraus11
Token without @Injectable decorator were allowed if other decorator was used
All provided or injected tokens must have @Injectable decorator
ViewEngine
Ivy
@MartinaKraus11
Queries search any nested level in the DOM
Queries will only search direct chield nodes in DOM hierarchy
ViewEngine
Ivy
@MartinaKraus11
Instance of TemplateRef, ViewContainerRef (and other special tokens) were shared on the same node
Requesting TemplateRef, ViewContainerRef (and other special tokens) return a new instance.
ViewEngine
Ivy
@MartinaKraus11
Accessing inputs through local refs are not longer support by default
@MartinaKraus11
https://angular.io/guide/ivy-compatibility
@MartinaKraus11
The compatibility compiler can require some changes to your library
Provide your libraries in a proper Angular Package Format ...
... or with proper entrypoint configuration
Do I need to add EVERYTHING manually?
@MartinaKraus11
ng-packagr transpiles your libraries to Angular Package Format
>>npm install -D ng-packagr
DEMO
@MartinaKraus11
Features:
https://github.com/ng-packagr/ng-packagr/blob/master/README.md
@MartinaKraus11
Ivy is an enabler: (For more dynamic applications)
Lib: support differences between both compilers
make sure you follow the Angular Package Format (ng-packagr)
me@martina-kraus.io
@MartinaKraus11
martina-kraus.io
Slides: http://bit.ly/slides-mk-ivy