refer :

https://blog.angularindepth.com/all-you-need-to-know-about-ivy-the-new-angular-engine-9cde471f42cf

https://blog.angularindepth.com/asynchronous-modules-and-components-in-angular-ivy-1c1d79d45bd3

https://blog.angularindepth.com/the-future-of-standalone-components-in-the-post-ivy-release-days-e7ed9b9b4dcd

https://blog.nrwl.io/metaprogramming-higher-order-components-and-mixins-with-angular-ivy-75748fcbc310

https://www.softwarearchitekt.at/aktuelles/architecture-with-ivy-a-possible-future-without-angular-modules/

https://www.softwarearchitekt.at/aktuelles/architecture-with-angular-ivy-part-2-higher-order-and-dynamic-components/

https://blog.ninja-squad.com/2019/05/07/what-is-angular-ivy/

https://blog.angularindepth.com/angular-ivy-change-detection-execution-are-you-prepared-ab68d4231f2c (change detech)

https://blog.angularindepth.com/ivy-engine-in-angular-first-in-depth-look-at-compilation-runtime-and-change-detection-876751edd9fd  (change detech)

https://netbasal.com/optimizing-angular-change-detection-triggered-by-dom-events-d2a3b2e11d87 (change detech)

听说 Angular 9 没有什么了不起的功能发布,只是将某个配置修改成默认而已. 团队真不给力丫...

修改的这个配置是渲染引擎, 名叫 ivy,好像是因为第 4 代所以叫这个名字.

它有什么不一样的地方呢 ?

主要是组件编辑后的代码不同了,对树摇友好一点. 代码好看一点. size 小一点.

1. 长相.

编辑后都把代码写进静态函数了, build 模板是直接使用调用式..elementstart 会直接调用 dom api 去创建 element (好像是这样)

注意那个 ɵfac 之后会讲到.

2. no more entry component.

以前要动态出组件挺麻烦的,要 entry component 而且 module 也不可以 lazyload

现在简单很多了

  open() {
import('./abc/abc.module').then((m) => {
ɵcreateInjector(m.AbcModule, this.injector);
this.dialog.open(AbcComponent, { width: '1000px' });
}); // import('./abc/abc.component').then((m) => {
// const factory = this.cfr.resolveComponentFactory(m.AbcComponent);
// this.target.createComponent(factory, 0, this.injector);
// }); // import('./abc/abc.component').then((m) => ɵrenderComponent(m.AbcComponent,
// { injector: this.injector, host: this.el.nativeElement }
// ));
}

直接 lazy load 然后链接 injector 给这个模块,就可以用任何组件了.

模块无需 entry component 也不用 export

@NgModule({
declarations: [AbcComponent, XyzComponent],
imports: [
CommonModule
],
// exports: [AbcComponent, XyzComponent],
// entryComponents: [AbcComponent]
})
export class AbcModule { }

注意:  如果你没用 import module 而是直接 append component 你会发现也是可以跑的, 但是如果这个 component 里面有依赖其它的 component 就不行了, 除非你没用使用 module, 而是通过组件自己去写依赖.

目前官方没用给出不写 module 的方式. 相信之后会出, 可能会长的像 2.0 rc 那样,那个年代 ngmodule 还没有出来呢...

另一个重点是 injector, 我们 import 过来后, 需要用这个 module build 一个 inujector, 因为这个 module 里面可能有 provider 然后才能 append component.

3. optional ng module

ivy 后, ng module 变得是一个 optional, 当然 ng module 为我们封装了很多好料, injector, detech change, life cycle 等等.

然后你不要用它,全部都要自己弄咯. 文章里有参考,我自己没有这个需求以后有才补上 demo.

4. HOC (height order component)

目前还感受不到它能做什么大事情. 它的功能是说,现在我们可以通过 decorator 去拦截 ɵfac (这个 ɵ(Greek Theta) 是因为目前这个方法是 private 的.)

拦截后我们可以重写 ɵfac

export function HOC() {
return (cmpType) => {
const originalFactory = cmpType.ɵfac;
cmpType.ɵfac = (...args: any) => {
const cmp = originalFactory(...args);
console.log('component instance', cmp); // 重点
return cmp;
};
};
} @HOC()
@Component({
selector: 'app-test-dialog',
templateUrl: './test-dialog.component.html',
styleUrls: ['./test-dialog.component.scss']
})
export class TestDialogComponent implements OnInit {

看重点,这里我们就可以获取到组件实例,然后可以做一个封装,比如修改一些接口等等的,可以算是装修模式吧. ngOnChange 就是用这个方式去实现的哦,它已经不是内置的 life cycle hook 了.

我们也可以通过类似方式去加强 life cycle hook.

4.I18n

ng 的 i18n 非常弱, 绝大部分功能从 v5 说要做到 v9 都没有实现.

v9 后已经被分离出来了,如果要使用的话需要 install package @angular/localize

之前 angular.json 里面配置 "i18nLocale": "en-US" 的话也会直接报错, 如果没有装 package 的话。
 

最新文章

  1. SQL分页
  2. Types of intraclass correlation coefficience (ICC)
  3. java工具类包
  4. Zabbix简介(第一章第一节)
  5. cocos2d-x学习笔记------动画人物跑起来吧!
  6. Android 使用图标字体库
  7. spring aop简单日志实例
  8. ResultSet 转为 List或者JavaBean
  9. 测试sql性能方法
  10. 进程waitpid()的用法
  11. jQuery + CSS3实现环形进度条
  12. yii2之数据验证
  13. 《Linux Device Drivers》第十八章 TTY驱动程序——note
  14. sqlserver给用户配置存储过程查看权限
  15. Could not find artifact cn.e3mall:e3mall-parent:pom:0.0.1-SNAPSHOT
  16. Akka并发编程框架 -概念模型(Akka.net或者Orleans)
  17. Tomcat Windows 系统下安装及注意事项
  18. UML类图关系大全【转】
  19. 09观察者模式ObServer
  20. gdal source code c++ make windows

热门文章

  1. make 实例 二 V56
  2. (信贷风控九)行为评分卡模型python实现
  3. osg Error osgearth_viewerd fails with "Loaded scene graph does not contain a MapNode
  4. 算法习题---5.5集合栈计算机(Uva12096)*****
  5. 聚类K-Means和大数据集的Mini Batch K-Means算法
  6. java.net.NoRouteToHostException: Cannot assign requested address 问题分析(端口被用完的解决方法)
  7. 怎样制作像delphi一样的启动欢迎画面?
  8. 【超分辨率】—图像超分辨率(Super-Resolution)技术研究
  9. 【转】百万年薪挖了p8,难道是水货?
  10. 【Leetcode_easy】905. Sort Array By Parity