javascript - => Angularjs。对于传入的值,我是否正确理解这一点?
问题描述
我正在学习关于 RxJs 6 的 Udemy 课程,并且需要问这个问题,因为这对我来说不是很清楚。
注意:这是我目前正在学习的提前输入教程。所以在 keyup 事件上,这个方法被触发了。
ngAfterViewInit() {
const searchLessons$ = fromEvent<any>(this.input.nativeElement, 'keyup')
.pipe(
map(event => event.target.value),
debounceTime(400),
distinctUntilChanged(),
// switchMap cancels prior calls.
switchMap(search => this.loadLessons(search))
);
const initialLessons$ = this.loadLessons();
this.lessons$ = concat(initialLessons$, searchLessons$);
}
代码是否意味着,
- 对于触发代码的所有事件,将从对loadLessons的已完成调用中收集响应
- 事件的值被引用为搜索
- 然后 => 将触发对loadLessons(search)的调用
- 继续 3:如果事件的值只是说一个值数组,这是否意味着对于 => 调用,将对loadLessons(search)的单独调用将传递给每个单独的数组值
- 继续 3: 还是只传入整个数组?
解决方案
这是每行解释:
ngAfterViewInit() {
const searchLessons$ = fromEvent<any>(this.input.nativeElement, 'keyup') // whenever keyup is triggered on this.input
.pipe(
map(event => event.target.value), // we extract input value from event target
debounceTime(400), // we wait for last event in 400ms span
distinctUntilChanged(), // we check that the input value did change
switchMap(search => this.loadLessons(search)) // and with that input value changed we call this.LoadLessons and then wait for its return
);
const initialLessons$ = this.loadLessons(); // this will call initial loadLeason
this.lessons$ = concat(initialLessons$, searchLessons$); // this will connect return of initial call and changes triggered by key up this is not secure for race conditions
}
广告1。输入时的所有按键事件
广告2。输入的值被引用为搜索
广告3。是的,它只会将数组作为参数推送
推荐阅读
- aws-lambda - 是否可以在 CodePipeline 失败时自定义 AWS 聊天机器人消息?
- javascript - 是否可以使用 javascript 记录客户端子资源完整性错误?
- c# - 用于在 Windows 7+ 上部署的 .NET 5.0 或 .NET Framework 3.5?
- c++ - 为什么将 `istream&` 用于临时的 `stringstream` 工作,但在使用 `stringstream&` 时却不行?
- java - 尝试使用 TomEE Microprofile 9 @Inject Microprofile Config 时出错
- python - 破折号回调函数中未固定的过滤器集
- java - 我们是否应该在 kubernetes 容器中设置 -Xmx(最大 Java 堆大小)
- node.js - 如何从 ssl 网站通过 https 加载 socketio?
- sql - 带有母子表选择的 Oracle 选择到 XML
- excel - 替换同一工作表上日期的多个值