• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript operators.scan函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中rxjs/operators.scan函数的典型用法代码示例。如果您正苦于以下问题:TypeScript scan函数的具体用法?TypeScript scan怎么用?TypeScript scan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了scan函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: initialize

 public initialize() {
   return {
     view: {
       base: this.intent.test().pipe(
         scan((acc, next: any) => acc + 1, 1),
         share(),
         startWith(1),
       ),
       test: this.intent.test().pipe(
         scan((acc, next: any) => acc + 1, 1),
         share(),
         startWith(1),
       ),
       test2: this.subject.pipe(
         map(({ type, payload, states }) => {
           switch (type) {
             case 'subject-test':
               return payload + states.test2;
             default:
               return payload;
           }
         }),
         startWith(1),
       ),
     },
   };
 }
开发者ID:brn,项目名称:react-mvi,代码行数:27,代码来源:factory.spec.ts


示例2: higherOrderScan

export function scan<T, R>(this: Observable<T>,
                           accumulator: (acc: T | Array<T> | R, value: T, index: number) => T | Array<T> | R,
                           seed?: T | R): Observable<R> {
  if (arguments.length >= 2) {
    return higherOrderScan(accumulator, seed)(this) as Observable<R>;
  }
  return higherOrderScan(accumulator)(this) as Observable<R>;
}
开发者ID:DallanQ,项目名称:rxjs,代码行数:8,代码来源:scan.ts


示例3: fromCollectionRef

export function sortedChanges<T>(query: Query, events: DocumentChangeType[]): Observable<DocumentChangeAction<T>[]> {
  return fromCollectionRef(query)
    .pipe(
      map(changes => changes.payload.docChanges()),
      scan((current, changes) => combineChanges(current, changes, events), []),
      map(changes => changes.map(c => ({ type: c.type, payload: c } as DocumentChangeAction<T>))));
}
开发者ID:Tetsumote,项目名称:angularfire2,代码行数:7,代码来源:changes.ts


示例4: switchMap

  return switchMap(obs => {
    return combineLatest(
               ...obs.map(o => o.pipe(take(1), startWith(INITIAL_VALUE as INTERIM_VALUES))))
        .pipe(
            scan(
                (acc: INTERIM_VALUES, list: INTERIM_VALUES[]) => {
                  let isPending = false;
                  return list.reduce((innerAcc, val, i: number) => {
                    if (innerAcc !== INITIAL_VALUE) return innerAcc;

                    // Toggle pending flag if any values haven't been set yet
                    if (val === INITIAL_VALUE) isPending = true;

                    // Any other return values are only valid if we haven't yet hit a pending call.
                    // This guarantees that in the case of a guard at the bottom of the tree that
                    // returns a redirect, we will wait for the higher priority guard at the top to
                    // finish before performing the redirect.
                    if (!isPending) {
                      // Early return when we hit a `false` value as that should always cancel
                      // navigation
                      if (val === false) return val;

                      if (i === list.length - 1 || val instanceof UrlTree) {
                        return val;
                      }
                    }

                    return innerAcc;
                  }, acc);
                },
                INITIAL_VALUE),
            filter(item => item !== INITIAL_VALUE), take(1)) as Observable<boolean|UrlTree>;
  });
开发者ID:KaneFreeman,项目名称:angular,代码行数:33,代码来源:prioritized_guard_value.ts


示例5: takeUntil2

  takeUntil2() {
    // emit value every 1s
    const source = interval(1000);
    // is number even?
    const isEven = val => val % 2 === 0;
    // only allow values that are even
    const evenSource = source.pipe(filter(isEven));
    // keep a running total of the number of even numbers out
    const evenNumberCount = evenSource.pipe(scan((acc, _) => acc + 1, 0));
    // do not emit until 5 even numbers have been emitted
    const fiveEvenNumbers = evenNumberCount.pipe(filter(val => val > 5));

    const example = evenSource.pipe(
      // also give me the current even number count for display
      withLatestFrom(evenNumberCount),
      map(([val, count]) => `Even number (${count}) : ${val}`),
      // when five even numbers have been emitted, complete source observable
      takeUntil(fiveEvenNumbers)
    );
    /*
    	Even number (1) : 0,
      Even number (2) : 2
    	Even number (3) : 4
    	Even number (4) : 6
    	Even number (5) : 8
    */
    const subscribe = example.subscribe(val => console.log(val));
  }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:28,代码来源:conditional.service.ts


示例6: it

  it('should pass current index to accumulator', () => {
    const values = {
      a: 1, b: 3, c: 5,
      x: 1, y: 4, z: 9
    };
    let idx = [0, 1, 2];

    const e1 =     hot('--a--b--c--|', values);
    const e1subs =     '^          !';
    const expected =   '--x--y--z--|';

    const scanFunction = (o: number, value: number, index: number) => {
      expect(index).to.equal(idx.shift());
      return o + value;
    };

    const scanObs = e1.pipe(
      scan(scanFunction, 0),
      finalize(() => {
        expect(idx).to.be.empty;
      })
    );

    expectObservable(scanObs).toBe(expected, values);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
开发者ID:MykhailoIskiv,项目名称:rxjs,代码行数:26,代码来源:scan-spec.ts


示例7:

export function auditTrail<T>(query: DatabaseQuery, events?: ChildEvent[]): Observable<SnapshotAction<T>[]> {
  const auditTrail$ = stateChanges<T>(query, events)
    .pipe(
      scan<SnapshotAction<T>>((current, action) => [...current, action], [])
    );
  return waitForLoaded<T>(query, auditTrail$);
}
开发者ID:PaulD11,项目名称:angularfire2,代码行数:7,代码来源:audit-trail.ts


示例8: multicats

 @Get('broadcast')
 multicats() {
   return this.client.send<number>({ cmd: 'broadcast' }, {})
     .pipe(
       scan((a, b) => a + b),
       take(2),
     );
 }
开发者ID:SARAVANA1501,项目名称:nest,代码行数:8,代码来源:redis-broadcast.controller.ts


示例9: scan1

 scan1() {
   const source = of(1, 2, 3);
   //  basic scan example, sum over time starting with zero
   const example = source.pipe(scan((acc, curr) => acc + curr, 0));
   //  log accumulated values
   //  output: 1,3,6
   const subscribe = example.subscribe(val => console.log(val));
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:8,代码来源:transforming.service.ts


示例10: omit

  useEpic((actor$) => {
    return actor$.pipe(
      rxFilter(RequestActor.isRequestActor),
      rxScan(
        (counts, actor: any) => {
          const parentActorType = actor.opts.parentActor.type;

          const count = counts[parentActorType] || 0;

          if (actor.stage === AsyncStage.STARTED) {
            return {
              ...counts,
              [parentActorType]: count + 1,
            };
          }

          if (count > 1) {
            return {
              ...counts,
              [parentActorType]: count - 1,
            };
          }

          return omit(counts, parentActorType);
        },
        {} as Dictionary<number>,
      ),
      rxTap((nextRequests) => {
        requesting$.next(size(nextRequests) > 0);
      }),
      rxIgnoreElements(),
    );
  });
开发者ID:querycap,项目名称:reactorx,代码行数:33,代码来源:useRequesting$.ts



注:本文中的rxjs/operators.scan函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript operators.sequenceEqual函数代码示例发布时间:2022-05-25
下一篇:
TypeScript operators.sampleTime函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap