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