本文整理匯總了TypeScript中rxjs.Observable.flatMap方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.flatMap方法的具體用法?TypeScript Observable.flatMap怎麽用?TypeScript Observable.flatMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs.Observable
的用法示例。
在下文中一共展示了Observable.flatMap方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
let reducer = (outputStream: Observable<Resource>, toResourceTypeExtension: string) => {
let toResourceType = env.resourceTypes.lookup(toResourceTypeExtension);
// Apply conversion transformations (from -> to) resource type.
if (fromResourceType !== null) {
let conversionTransformers = fromResourceType.conversions[toResourceTypeExtension];
if (!!conversionTransformers) {
outputStream = outputStream.flatMap(outputResource =>
env.behaviors.applySequenceOfTransformsToResource(outputResource, fromResourceType, conversionTransformers)
);
}
}
// Prepare for next iteration.
fromResourceType = toResourceType;
// Apply process transformations for the current resource type.
return outputStream.flatMap(outputResource =>
env.behaviors.processResource(outputResource, toResourceType)
);
};
示例2: ngOnInit
public ngOnInit(): void {
let { type, data, resetPosition }: any = this.options;
type = type || "any";
resetPosition = resetPosition === undefined ? true : resetPosition;
this.dragStart
.flatMap(e => Observable.of(e).delay(150).takeUntil(this.dragEnd))
.map((e: any) => {
e.preventDefault();
this.el.classList.add("dragged");
let { left, top }: any = this.el.style;
let clientX: number = e.clientX || e.touches[0].clientX;
let clientY: number = e.clientY || e.touches[0].clientY;
return {
left: clientX,
top: clientY,
offsetLeft: DraggableDirective.offsetToNumber(left),
offsetTop: DraggableDirective.offsetToNumber(top)
};
})
.flatMap((source: any) => this.dragMove
.map((e: any) => {
let clientX: number = e.clientX || e.touches[0].clientX;
let clientY: number = e.clientY || e.touches[0].clientY;
this.service.dragged.next({ clientX, clientY});
return {
left: clientX - source.left + source.offsetLeft,
top: clientY - source.top + source.offsetTop
};
})
.takeUntil(this.dragEnd.do((e: any) => {
this.el.classList.remove("dragged");
this.service.dropped.next({ type, data });
if (resetPosition) {
this.resetPosition();
}
}))
)
.subscribe(({ top, left }: any) => {
this.el.style.left = left + "px";
this.el.style.top = top + "px";
});
}
示例3: process
process(observable: Observable<any>, context?: any): Observable<any> {
return observable.flatMap(o => this.transformer.process(o, context));
}