当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript operators.switchMap函数代码示例

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


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

示例1: ngxsOnInit

  ngxsOnInit({ dispatch }: StateContext<ShopProductsModel>) {
    concat(
      this.stateService.getInitialState('', 'products').pipe(take(1)),
      /* LOGIN: */
      this.store$.select(UserState.isLoggedIn).pipe(
        pairwise(),
        filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
        switchMap(() => this.stateService.getInitialState('', 'products').pipe(take(1)))
      )
    ).subscribe((products) => {
      dispatch(new InitShopProductsAction(products));
    });

    // Update products from server on entry update (name, attribute, instock, reservations)
    this.actions$.pipe(
      ofActionSuccessful(UpdateSectionEntryFromSyncAction),
      filter(action => {
        const actions = ['cartTitle', 'cartPrice', 'cartAttributes'];
        const prop = action.path.split('/').pop();
        return actions.indexOf(prop) > -1;
      }),
      switchMap(() => this.stateService.getInitialState('', 'products', true).pipe(take(1)))

    ).subscribe((products) => {
      dispatch(new InitShopProductsAction(products));
    });
  }
开发者ID:berta-cms,项目名称:berta,代码行数:27,代码来源:shop-products.state.ts

示例2: test

 test(`invoke "update" action`, (done) => {
   const playlist = new KalturaPlaylist({
     name: "tstest.PlaylistTests.test_createRemote",
     referenceId: "tstest.PlaylistTests.test_update",
     playlistType: KalturaPlaylistType.staticList
   });
   expect.assertions(1);
   kalturaClient.request(new PlaylistAddAction({playlist}))
     .pipe(
     switchMap(({id}) => {
         playlist.name = "Changed!";
         return kalturaClient.request(new PlaylistUpdateAction({id, playlist}));
       }
     ),
     switchMap(({id, name}) => {
       asyncAssert(() => {
         expect(name).toBe("Changed!");
       });
       return kalturaClient.request(new PlaylistDeleteAction({id}));
     }))
     .subscribe(() => {
           done();
       },
       error => {
         done.fail(error);
       });
 });
开发者ID:kaltura,项目名称:clients-generator,代码行数:27,代码来源:service-playlist.spec.ts

示例3: ngOnInit

 ngOnInit() {
   this.block$ = combineLatest(
     this.config.currentChain$,
     this.route.paramMap.pipe(
       switchMap(params => of(params.get('hash'))),
       filter((hash): hash is string => typeof hash === 'string')
     )
   ).pipe(
     switchMap(([chain, hash]) => this.apiService.streamBlock(chain, hash))
   );
 }
开发者ID:bitjson,项目名称:bitcore,代码行数:11,代码来源:block.page.ts

示例4: function

const shortCachesResolve = ['ConfigSelectors', 'ConfigureState', 'ConfigEffects', '$transition$', function(ConfigSelectors, ConfigureState, {etp}, $transition$) {
    if ($transition$.params().clusterID === 'new')
        return Promise.resolve();
    return from($transition$.injector().getAsync('_cluster')).pipe(
        switchMap(() => ConfigureState.state$.pipe(ConfigSelectors.selectCluster($transition$.params().clusterID), take(1))),
        switchMap((cluster) => {
            return etp('LOAD_SHORT_CACHES', {ids: cluster.caches, clusterID: cluster._id});
        })
    )
    .toPromise();
}];
开发者ID:gridgain,项目名称:gridgain,代码行数:11,代码来源:states.ts

示例5: provideMigrations

export function provideMigrations(area: chrome.storage.StorageArea): MigratableStorageArea {
    const migrations = new Subject<MigrateFunc>()
    const getCalls = new ReplaySubject<any[]>()
    const setCalls = new ReplaySubject<any[]>()

    const migrated = migrations.pipe(
        switchMap(
            migrate =>
                new Observable(observer => {
                    area.get(items => {
                        const { newItems, keysToRemove } = migrate(items as StorageItems)
                        area.remove(keysToRemove || [], () => {
                            area.set(newItems || {}, () => {
                                observer.next()
                                observer.complete()
                            })
                        })
                    })
                })
        ),
        take(1),
        share()
    )

    const initializedGets = migrated.pipe(switchMap(() => getCalls))
    const initializedSets = migrated.pipe(switchMap(() => setCalls))

    initializedSets.subscribe(args => {
        area.set.apply(area, args)
    })

    initializedGets.subscribe(args => {
        area.get.apply(area, args)
    })

    const get: chrome.storage.StorageArea['get'] = (...args) => {
        getCalls.next(args)
    }

    const set: chrome.storage.StorageArea['set'] = (...args) => {
        setCalls.next(args)
    }

    return {
        ...area,
        get,
        set,

        setMigration: migrate => {
            migrations.next(migrate)
        },
    }
}
开发者ID:JoYiRis,项目名称:sourcegraph,代码行数:53,代码来源:storage_migrations.ts

示例6: constructor

  constructor(ref: DocumentReference) {
    this.ref = ref;

    this.index = new PackedIndex();

    this.data().subscribe(data => this.index.setInstitution(data));

    this.gradeDistribution = this.data().pipe(
      switchMap(data => Axios.get(`${data.cloudFunctionsUrl}/api/grades`)),
      map(
        (response: { data: any }) =>
          Object.freeze(response.data) as Distribution
      ),
      publishReplay(1),
      refCount()
    );
    this.courseRanking = combineLatest(
      this.getGradeDistribution().pipe(
        map(distribution => {
          return Object.entries(distribution).reduce((obj, [course, data]) => {
            return {
              ...obj,
              [course]: 2 * Object.values(data).reduce((a, b) => a + b, 0)
            };
          }, {});
        })
      ),
      this.index.getSequences().pipe(
        switchMap(sequences => {
          return combineLatest(
            sequences.map(sequence => this.index.getSparseSequence(sequence))
          );
        })
      )
    ).pipe(
      map(([courseRanking, sparseSequences]) => {
        sparseSequences.forEach(sequence => {
          // Promote the rank of each course in the sequence to the max.
          const max =
            sequence
              .map(course => courseRanking[course] | 0)
              .reduce((a, b) => Math.max(a, b)) + 1;
          sequence.forEach(course => (courseRanking[course] = max));
        });
        return courseRanking;
      }),
      publishReplay(1),
      refCount()
    );
  }
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:50,代码来源:institution.ts

示例7: openConfigureDialog

  openConfigureDialog() {
    const dialogSub = this.dialog.open(ConfigureComponent, {
      width: `1024px`,
      data: {
        chart$: this.chartDetails$,
      }
    }).afterClosed()
      .pipe(
        filter(values => values !== undefined),
        map(
          values => this.chartDetails$.pipe(
            map(chart => {
              chart.values = values;
              return chart;
            })
          )
        ),
        switchMap(values => values),
        tap((updatedValues) => {
          this.store.dispatch(new SetAppDetails(updatedValues));
        })
      ).subscribe(val => {
        console.log('res1', val);
      });

    this.subscriptons.add(dialogSub);
  }
开发者ID:supergiant,项目名称:supergiant,代码行数:27,代码来源:app-details.component.ts

示例8: ofType

export const updateDisplayEpic = (
  action$: ActionsObservable<NewKernelAction>
) =>
  // Global message watcher so we need to set up a feed for each new kernel
  action$.pipe(
    ofType(actions.LAUNCH_KERNEL_SUCCESSFUL),
    switchMap((action: NewKernelAction) =>
      action.payload.kernel.channels.pipe(
        ofMessageType("update_display_data"),
        map((msg: JupyterMessage) =>
          actions.updateDisplay({
            content: msg.content,
            contentRef: action.payload.contentRef
          })
        ),
        catchError(error =>
          of(
            actions.updateDisplayFailed({
              error,
              contentRef: action.payload.contentRef
            })
          )
        )
      )
    )
  );
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:26,代码来源:execute.ts

示例9: ngOnInit

 ngOnInit(): void {
   this.route.params
     .pipe(switchMap((params: Params) => this.auditService.getLogPerson(params['id'])))
     .subscribe((logs: Array<ActionLog>) => {
       this.logs = logs;
     });
 }
开发者ID:digitaldeacon,项目名称:memberhive,代码行数:7,代码来源:audit-log.component.ts

示例10: publishDocument

 requirements.map(node => {
   if (typeof node === "string") {
     if (node.startsWith("subprograms")) {
       // Resolve the subprogram.
       return publishDocument(
         this.subprogramsRef.doc(node.split("/")[1])
       ).pipe(
         switchMap(result => {
           if (!result) {
             console.error("Could not resolve subprogram: " + node);
             return of({ display: "Specification error" });
           }
           return this.resolve(JSON.parse(result.requirements)).pipe(
             map(requirements => ({
               display: result.display,
               requirements
             }))
           );
         })
       );
     } else {
       return of(node);
     }
   } else if (node.requirements) {
     return this.resolve(node.requirements).pipe(
       map(requirements => ({ ...node, requirements }))
     );
   } else {
     return of(node);
   }
 })
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:31,代码来源:program.ts


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