什么是操作符,在 rxjs 中 map, filter 函数都是操作符。操作符:一个操作符是返回一个 Observable 对象的函数。
rxjs 中有 60 多个操作符,在理论开发过程中该应用哪个操作符适合,把每个操作符的性能和个性都都记下来有点艰难,如果有适合的分类办法,把操作符分类,晓得每一类操作符的特点,当咱们遇到问题,依据要解决问题和各类操作符的特点,抉择适合的操作符,开发就会更高效。
分类如下,当前分享每类的应用,
操作符
创立类
- from
- create
- of
- range
- generate
- repeat/repeatWhen
- throw
- empty
- ajax
- never
- defer
- fomPromise
- interval
- timer
- fromEvent
合并类
- concat/concatAll
- merge/mergeAll
- zip/zipAll
- combineLatest/conbineAll/withLatestFrom
- race
- startWith
- forkJoin
- switch/exhaust
辅助工具类
- count
- max/min
- reduce
- every
- find/findIndex
- isEmpty
- defaultEmpty
过滤类
- filter
- first
- last
- take
- takeLast
- takeWhile/takeUntil
- skip
- skipWhile/skipUntil
- throttleTime/debounceTime/auditTime
- throttle/debounce/audit
- sample/sampleTime
- distnct
- single
- elementAt
- ignoreElements
- distnctUtilChanged/distnctUntilKeyChanged
转换类
- map
- mapTo
- pluck
- windowTime/
- scan/mergeScan
错误处理类
- catch
- retry/retryWhen
- finally
多播
- multicast
- publishLast
- publishReplay
- publishBehavior