本文整理汇总了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));
}