當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript BehaviorSubject.map方法代碼示例

本文整理匯總了TypeScript中rxjs/BehaviorSubject.BehaviorSubject.map方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BehaviorSubject.map方法的具體用法?TypeScript BehaviorSubject.map怎麽用?TypeScript BehaviorSubject.map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs/BehaviorSubject.BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.map方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

export default function(options: CanvasOptions) {
  const write  = new Subject<DragDeltaLog>();
  const clear  = new Subject<any>();
  const scale  = new BehaviorSubject<any>(true);
  const toggle = new Subject<any>();

  const canvas  = options.canvasElement as HTMLCanvasElement;
  const context = canvas.getContext("2d");
  if (context === null) {
    throw new TypeError('unreachable: canvas should be not `null`');
  }

  write.subscribe(writeCanvasTo(context, options.color));
  clear.subscribe(clearCanvasTo(context));

  scale
    .map(() => window.innerWidth)
    .subscribe(attributeAssignOf(canvas, 'width'));
  scale
    .map(() => window.innerHeight)
    .subscribe(attributeAssignOf(canvas, 'height'));

  toggle
    .scan((acc) => !acc, false)
    .map((bool) => bool ? 'false' : 'true')
    .subscribe(attributeAssignOf(canvas, 'aria-hidden'));

  return {
    cvWrite  : write,
    cvClear  : clear,
    cvToggle : toggle,
    cvScale  : scale
  };

}
開發者ID:1000ch,項目名稱:Talkie,代碼行數:35,代碼來源:canvas.ts

示例2: function

/**
 * compute ratio
 */
export default function(options: ResponsiveOptions) {

  const scaleSubject = new BehaviorSubject<any>(true);
  const scaleFn = compose(centeringOf(options.target), scalingOf(options.target));

  const hRatio = scaleSubject.map(horizontalRatioOf(options.width));
  const vRatio = scaleSubject.map(verticalRatioOf(options.height));

  const currentRatio = Observable.combineLatest(hRatio, vRatio).map((hv) => Math.min(hv[0], hv[1]));
  currentRatio.subscribe(scaleFn);

  return {
    scale        : scaleSubject,
    currentRatio : currentRatio
  };
}
開發者ID:1000ch,項目名稱:Talkie,代碼行數:19,代碼來源:responsive.ts

示例3: 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/BehaviorSubject.BehaviorSubject.map方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。