當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript operators.scan函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。