本文整理汇总了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));
});
}
示例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);
});
});
示例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))
);
}
示例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();
}];
示例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)
},
}
}
示例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()
);
}
示例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);
}
示例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
})
)
)
)
)
);
示例9: ngOnInit
ngOnInit(): void {
this.route.params
.pipe(switchMap((params: Params) => this.auditService.getLogPerson(params['id'])))
.subscribe((logs: Array<ActionLog>) => {
this.logs = logs;
});
}
示例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);
}
})