2021年1月25日
摘要:
<ul *ngFor="let item of list"> <li>{{show(item.label)}}</li> </ul> 上面的代码每次变化检测的周期都会执行,即使item.label没有改变 此时应该使用Pure Pipes来代替show函数 @Pipe({ name: 'showla
阅读全文
posted @ 2021-01-25 16:15
chen8840
阅读(80)
推荐(0)
2021年1月20日
摘要:
angular里面变化检测是非常频繁的发生的,如果你像下面这样写代码 <div> {{hello()}} </div> 则每次变化检测都会执行hello函数,如果hello函数十分耗时,则会出现占用CPU高的问题。 这时,推荐使用OnPush策略和immutable.js来提升angular应用的性
阅读全文
posted @ 2021-01-20 17:05
chen8840
阅读(258)
推荐(0)
2021年1月14日
摘要:
一个angular组件,他的生命周期是这样的 update bound properties for all child components/directives call ngOnInit, OnChanges and ngDoCheck lifecycle hooks on all child
阅读全文
posted @ 2021-01-14 12:01
chen8840
阅读(1769)
推荐(0)
2020年12月10日
摘要:
一段会报错的angular代码 @Injectable() class Socket { constructor(private buffer: Buffer) { } } console.log(Buffer); // undefined @Injectable() class Buffer {
阅读全文
posted @ 2020-12-10 12:43
chen8840
阅读(357)
推荐(0)
2020年7月17日
摘要:
.colorPaletteMixin() { @functions: ~`(function() { this.colorPalette = function() { return '123px'; }; })()`; } // It is hacky way to make this functi
阅读全文
posted @ 2020-07-17 10:06
chen8840
阅读(3169)
推荐(0)
2020年5月29日
摘要:
跑出父作用域的闭包叫做逃逸闭包 逃逸闭包如果引用了环境变量,那么需要使用move关键字,或者是FnOnce也行 fn test() -> impl Fn() { let s = String::from(""); move || { println!("{}", s); } } fn main()
阅读全文
posted @ 2020-05-29 17:33
chen8840
阅读(382)
推荐(0)
摘要:
move关键字是强制让环境变量的所有权转移到闭包中而不管是不是发生了所有权的转移 move关键字和匿名函数是否是FnOnce没有必然联系,之和匿名函数体有关 当匿名函数体里转移了环境变量的所有权的时候,匿名函数就是FnOnce。 当匿名函数体里改变了环境变量的值的时候,匿名函数就是FnMut。 否则
阅读全文
posted @ 2020-05-29 15:04
chen8840
阅读(683)
推荐(0)
摘要:
继承结构 FnOnce FnMut: FnOnce Fn: FnMut FnOnce就是说会转移闭包捕获变量的所有权,在闭包前加上move关键字可以限定此闭包为FnOnce move关键字是强制让环境变量的所有权转移到闭包中而不管是不是发生了所有权的转移 #![feature(core_intrin
阅读全文
posted @ 2020-05-29 10:42
chen8840
阅读(735)
推荐(0)
2020年5月28日
摘要:
生命周期一般用来修饰引用类型,但是他也可以用来修饰泛型和类型的 比如以下代码 trait Foo {} struct FooImpl<'a> { s: &'a u32 } impl<'a> Foo for FooImpl<'a> {} fn foo<'a>(s: &'a u32) -> Box<dy
阅读全文
posted @ 2020-05-28 09:24
chen8840
阅读(111)
推荐(0)
2020年5月22日
摘要:
用stream.read_to_end是不行的,tcpstream不是文件没有明确的结束符 需要先读取http header节,再找Content-Length header,然后读取body。 这是http请求的结构 有个github可以参考,地址是https://github.com/lthei
阅读全文
posted @ 2020-05-22 14:36
chen8840
阅读(1739)
推荐(0)