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