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


TypeScript rxjs.BehaviorSubject類代碼示例

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


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

示例1: constructor

 constructor(private authService: AuthService, private router: Router) {
   this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem('currentUser')));
   this.currentUser = this.currentUserSubject.asObservable();
 }
開發者ID:arner,項目名稱:saevis,代碼行數:4,代碼來源:authentication.service.ts

示例2: function

  return function(target: Object, key: string) {
    if (!isDebugMode()) {
      return;
    }

    const takeLast = config.takeLast || 5;
    const label = config.label || key;
    const metaTarget = target.constructor;
    const debugObservables = getOwnMetadata(OBSERVABLE_KEY, metaTarget) || [];
    const valueHistory = new BehaviorSubject([]);

    let observable = target[key];
    let lastEmissions = [];

    const get = function() {
      return observable;
    };

    const set = function(newValue: Observable<any>) {
      lastEmissions = [];
      valueHistory.next(lastEmissions);

      // Patch subscription method so we can log when someone subscribes
      if (config.logSubscriptions) {
        const orig = newValue.subscribe;
        newValue.subscribe = function(...args) {
          console.log(
            `${label} subscribed to:\n`,
            new Error().stack
              .split('\n')
              .slice(5) // Skip this call and the ones up to devmod's monkey patch
              .map(v => `\t ${v.trim()}`)
              .join('\n')
          );

          return orig.call(newValue, ...args);
        };
      }

      // Store previously emitted values in BehaviorSubject
      observable = newValue.pipe(
        tap(v => {
          if (config.log) {
            console.log(`${label} emitted`, v);
          }
          lastEmissions = lastEmissions
            .concat({
              at: new Date(),
              value: v
            })
            .slice(-1 * takeLast);
          valueHistory.next(lastEmissions);
        })
      );
    };

    Object.defineProperty(target, key, {
      get,
      set,
      enumerable: true,
      configurable: true
    });

    debugObservables.push({ key, obs: valueHistory, takeLast, label });

    defineMetadata(OBSERVABLE_KEY, debugObservables, metaTarget);
  };
開發者ID:cybernetics,項目名稱:devmod,代碼行數:67,代碼來源:developer-observable.ts

示例3: setTimeout

 setTimeout(() => {
     subject$.error("error " + i);
     error = true;
 }, 1000)
開發者ID:chrigu,項目名稱:rxjs-experiments,代碼行數:4,代碼來源:behaviorSubject.error.ts

示例4:

export const deselectActivity = () => {
    selectedActivity$().next({});
}
開發者ID:kpreeti096,項目名稱:BotFramework-Emulator,代碼行數:3,代碼來源:settings.ts

示例5: resolve

 .subscribe(response => {
     this.onBoardChanged.next(this.board);
     resolve(this.board);
 }, reject);
開發者ID:karthik12ui,項目名稱:fuse-angular-full,代碼行數:4,代碼來源:scrumboard.service.ts

示例6: getSnapshot

	// ---
	// PUBLIC METHODS.
	// ---

	// I get the current state snapshot.
	public getSnapshot() : StateType {

		return( this.stateSubject.getValue() );

	}
開發者ID:bennadel,項目名稱:JavaScript-Demos,代碼行數:10,代碼來源:simple.store.ts

示例7: resolve

 .subscribe((response: any) => {
     this.orders = response;
     this.onOrdersChanged.next(this.orders);
     resolve(response);
 }, reject);
開發者ID:karthik12ui,項目名稱:fuse-angular-full,代碼行數:5,代碼來源:orders.service.ts

示例8: resolve

 .subscribe((response: any) => {
     this.tableData = response;
     console.log("data in getTable",this.tableData),
     this.onDataChanged.next(this.tableData);
     resolve(response);
 }, reject);
開發者ID:,項目名稱:,代碼行數:6,代碼來源:

示例9: delete

 delete() {
     this.tokenSubject.next("");
 }
開發者ID:urandom,項目名稱:readeef,代碼行數:3,代碼來源:auth.ts

示例10: tokenObservable

 tokenObservable() : Observable<string> {
     return this.tokenSubject.pipe(
         map(auth => (auth || "").replace("Bearer ", "")),
         throttle(v => interval(2000)),
     );
 }
開發者ID:urandom,項目名稱:readeef,代碼行數:6,代碼來源:auth.ts


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