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


TypeScript BehaviorSubject.asObservable方法代码示例

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


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

示例1: constructor

 constructor() {
   this._data = this.emptyData(); // Initialize session data with empty default values
   let storedData = this.retrieve();
   if (storedData) {
     Object.assign(this._data, storedData);
   }
   this.dataSubject = new BehaviorSubject(this._data);
   this.data = this.dataSubject.asObservable();
 }
开发者ID:StudioProcess,项目名称:imagetool,代码行数:9,代码来源:session.service.ts

示例2: constructor

    constructor() {
        this.connections = [];
        this._onUpdate = new BehaviorSubject([]);
        this.onUpdate = this._onUpdate.asObservable();

    }
开发者ID:it7-solutions,项目名称:networking-public-plugin,代码行数:6,代码来源:connections.service.ts

示例3: constructor

  constructor(
    private zone: NgZone
  ) {
    this.window = getWindow();
    this.document = getDocument();

    const initialFocus = this.document["visibilityState"] === "visible"
      ? DetailedFocusStates.TabFocus
      : DetailedFocusStates.TabBlur;

    this.detailedFocusSubject = new BehaviorSubject<DetailedFocusStates>(initialFocus);

    // Wire up the detailed focus observable
    //
    this.detailedFocus$ = this.detailedFocusSubject
      .asObservable()
      .distinctUntilChanged();

    // Now wire up the more generic observable by mapping the detailed values to the
    //  broader ones. We also add distinct until changed because we might get both
    //  a tab and window event fired, and we don't want to emit duplicates
    //
    this.focus$ = this.detailedFocus$
      .map((focus) => {
        switch (focus) {
          case DetailedFocusStates.WindowFocus:
          case DetailedFocusStates.TabFocus:
            {
              return FocusStates.Focus;
            }
        }
        return FocusStates.Blur;
      })
      .distinctUntilChanged();


    this.zone.run(() => {

      this.document.addEventListener("visibilitychange", () => {
        if (document.visibilityState === "visible") {
          this.detailedFocusSubject.next(DetailedFocusStates.TabFocus);
        } else {
          this.detailedFocusSubject.next(DetailedFocusStates.TabBlur);
        }
      });

      /////////////////////////////////////////
      // check if browser window has focus		
      let notIE = (this.document.documentMode === undefined),
        isChromium = this.window.chrome;

      if (notIE && !isChromium) {

        // checks for Firefox and other  NON IE Chrome versions
        this.window.on("focusin",
          () => {

            setTimeout(() => {
              this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);

            },
              300);

          });

        this.window.on("focusout", () => {
          this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);

        });

      } else {

        // checks for IE and Chromium versions
        if (this.window.addEventListener) {

          // bind focus event
          this.window.addEventListener("focus", (event: any) => {

            setTimeout(() => {
              this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
            },
              300);

          },
            false);

          // bind blur event
          this.window.addEventListener("blur", (event: any) => {
            this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);
          },
            false);

        } else {

          // bind focus event
          this.window.attachEvent("focus", (event: any) => {

            setTimeout(() => {
              this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
            },
//.........这里部分代码省略.........
开发者ID:sstorie,项目名称:experiments,代码行数:101,代码来源:window-focus.service.ts

示例4: getCurrentUser

 getCurrentUser(): Observable<User> {
     return this.currentUser.asObservable().share();
 }
开发者ID:mayacoda,项目名称:stories,代码行数:3,代码来源:user.service.ts

示例5: getTheme

 getTheme() {
     return this.theme.asObservable();
 }
开发者ID:colinjlacy,项目名称:themingApp,代码行数:3,代码来源:settings.service.ts

示例6: constructor

 constructor() {
   this._counties$ = new BehaviorSubject([]);
   this.counties$ = this._counties$.asObservable();
 }
开发者ID:praetorxyn,项目名称:angular2-interactive-map,代码行数:4,代码来源:county.service.ts

示例7: getActiveTheme

 getActiveTheme() {
   return this.theme.asObservable();
 }
开发者ID:WarriorsWCH,项目名称:ionic-app,代码行数:3,代码来源:settings.ts


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