【发布时间】:2017-10-20 00:08:18
【问题描述】:
在这个Angular decorator tutorial 中,教程解释了throttle 装饰器(lodash throttle 函数)可以这样制作:
import t from 'lodash.throttle';
export function throttle( milliseconds : number = 500 ) : MethodDecorator {
return function ( target : any, propertyKey : string, descriptor : PropertyDescriptor ) {
const original = descriptor.value;
descriptor.value = t(original, milliseconds);
return descriptor;
};
}
并在下面的类中使用
@Component({
selector: 'app-posts-page',
template: `
<posts [posts]="posts$ | async"></posts>
`
})
export class PostsPageComponent {
constructor( private store : Store<any> ) {
this.posts$ = store.select('posts');
}
@HostListener('document:scroll')
@throttle()
scroll() {
console.log('scroll');
}
}
我想知道油门是如何改变滚动功能的。谁能解释或让我知道如何查看编译后的代码?谢谢!
【问题讨论】:
标签: javascript angular angular-decorator