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


TypeScript Subject.withLatestFrom方法代码示例

本文整理汇总了TypeScript中rxjs/Subject.Subject.withLatestFrom方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subject.withLatestFrom方法的具体用法?TypeScript Subject.withLatestFrom怎么用?TypeScript Subject.withLatestFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs/Subject.Subject的用法示例。


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

示例1: constructor

    constructor() {
        this._tagOperation$ = new Subject<ICreateTagOperation>();
        this._create$ = new Subject<number[]>();
        this._delete$ = new Subject<void>();

        this._configuration$ = new Subject<ITagConfiguration>();

        this._tag$ = this._tagOperation$
            .scan<OutlineCreateTag>(
                (tag: OutlineCreateTag, operation: ICreateTagOperation): OutlineCreateTag => {
                    return operation(tag);
                },
                null)
            .share();

        this._create$
            .withLatestFrom(
                this._configuration$,
                (coordinate: number[], type: ITagConfiguration): [number[], ITagConfiguration] => {
                    return [coordinate, type];
                })
            .map<ICreateTagOperation>(
                (ct: [number[], ITagConfiguration]): ICreateTagOperation => {
                    return (tag: OutlineCreateTag): OutlineCreateTag => {
                        let coordinate: number[] = ct[0];
                        let configuration: ITagConfiguration = ct[1];

                        if (configuration.createType === "rect") {
                            let geometry: RectGeometry = new RectGeometry([
                                coordinate[0],
                                coordinate[1],
                                coordinate[0],
                                coordinate[1],
                            ]);

                            return new OutlineCreateTag(geometry, { color: configuration.createColor });
                        } else if (configuration.createType === "polygon") {
                            let geometry: PolygonGeometry = new PolygonGeometry([
                                [coordinate[0], coordinate[1]],
                                [coordinate[0], coordinate[1]],
                                [coordinate[0], coordinate[1]],
                            ]);

                            return new OutlineCreateTag(geometry, { color: configuration.createColor });
                        }

                        return null;
                    };
                })
            .subscribe(this._tagOperation$);

        this._delete$
            .map<ICreateTagOperation>(
                (): ICreateTagOperation => {
                    return (tag: OutlineCreateTag): OutlineCreateTag => {
                        return null;
                    };
                })
            .subscribe(this._tagOperation$);
    }
开发者ID:Caboosey,项目名称:mapillary-js,代码行数:60,代码来源:TagCreator.ts

示例2: function

/**
 * paging control
 */
export default function(options: PagingOptions) {

  const next    = new Subject<any>();
  const prev    = new Subject<any>();
  const move    = new Subject<number>();
  const current = new BehaviorSubject<number>(options.startPage || 1);

  const currentPage: Observable<number> = current
    .map(inRangeOf(1, options.endPage))
    .distinctUntilChanged();

  const _next = next.withLatestFrom(currentPage, (_, page) => page).map((v) => v + 1);
  const _prev = prev.withLatestFrom(currentPage, (_, page) => page).map((v) => v - 1);
  const _move = move.map((v) => v /* noop */);

  const percentString = currentPage.map(percentOf(options.endPage));
  const currentSlide  = currentPage.map((i) => options.slideElements[i - 1]);

  Observable.merge(_next, _prev, _move).subscribe(current);

  currentSlide.subscribe(function(current) {
    options.slideElements.forEach(toInvisible);
    current && toVisible(current);
  });

  return {
    current : currentPage,
    start   : currentPage.filter((v) => v === 1),
    end     : currentPage.filter((v) => v === options.endPage),
    changed : currentSlide,
    percent : percentString,
    next    : next,
    prev    : prev,
    move    : move
  };
}
开发者ID:1000ch,项目名称:Talkie,代码行数:39,代码来源:paging.ts


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