當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。