angular - Concat给出警告并且不会执行
问题描述
以下方法forkJoin
可以正常工作,但是 . . .
unifiedSearch : Function = (query: string) : Observable<UnifiedSearch> => {
return forkJoin(this.searchService.gitSearch(query), this.codeSearchService.codeSearch(query))
.map( (response : [GitSearch, GitCodeSearch]) => {
return {
'repositories' : response[0],
'code': response[1]
}
})
}
. . . 我试图将其转换concat
为作业的一部分,但是在编译时,我收到了一堆警告,并且浏览器中没有任何内容。
unifiedSearch : Function = (query: string) : Observable<UnifiedSearch> => {
return concat(this.searchService.gitSearch(query), this.codeSearchService.codeSearch(query))
.map( (response) => {
return {
'repositories' : response[0],
'code': response[1]
}
})
}
作为参考,这里是“统一搜索”界面:
import {GitSearch} from './git-search';
import { GitCodeSearch } from './git-code-search';
export interface UnifiedSearch {
repositories: GitSearch,
code: GitCodeSearch
}
如果有帮助,以下是我收到的警告:
./node_modules/rxjs/Observable/of.js
There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:
* C:\Users\Johnathan\advanced_angular\node_modules\rxjs\Observable\of.js
Used by 1 module(s), i. e.
C:\Users\Johnathan\advanced_angular\node_modules\rxjs\Observable\concat.js
* C:\Users\Johnathan\advanced_angular\node_modules\rxjs\observable\of.js
Used by 2 module(s), i. e.
C:\Users\Johnathan\advanced_angular\node_modules\@angular\common\@angular\common\http.es5.js
任何想法为什么该concat
版本不起作用?谢!
解决方案
concat
并且forkJoin
工作方式有所不同。
concat
按照发出的顺序从每个源发出每个值,并且顺序作为concat
运算符的参数给出。一旦一个源完成,它就会移动到源数组中的下一个。
forkJoin
将给出每个 observable 最后发出的值,然后在数组中返回这些值。它会等到所有给定的可观察对象都完成后才会发出。
以以下为例:
const source1 = of(1, 2);
const source2 = of(3, 4);
concat(source1, source2).subscribe(v => console.log(v))
// output (each line is new emit)
// 1
// 2
// 3
// 4
forkJoin(source1, source2).subscribe(v => console.log(v))
// output (each line is new emit)
// [2, 4]
您可能希望查看 usingcombineLatest
来组合来自每个源的发射,并在每次源 observable 之一发射时发射组合的最新值。这和之间的区别在于forkJoin
,combineLatest
每次源 observables 发出时都会发出,而forkJoin
只有在所有源 observables 完成后才发出。
推荐阅读
- grafana - 在普罗米修斯查询的右侧使用度量
- c++ - 类对象在 int main() 中为“未定义”
- keras - 功能 API/多输入模型超参数优化
- ruby-on-rails - 找到收入超过 10 年的公司
- javascript - 将厘米转换为英尺和英寸
- python - 使用 Jupyter notebook 在 Matplotlib 中执行 python 脚本文件,但它总是不显示数字。为什么?
- java - 在 Java 8 中为什么我们不能使用方法引用将 Math.random() 转换为 Math::random
- c# - 迭代变量如何只读?
- windows - pkg-config 已安装但未找到
- php - php邮件功能在新服务器中不起作用