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


TypeScript BehaviorSubject.subscribe方法代碼示例

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


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

示例1: it

    it('resets to false after executing', (done) => {
      const isExecuting = new BehaviorSubject(false);
      const cmd = new ReactiveCommand(testOwner, x => true);
      let count = 0;

      cmd.isExecuting.subscribe(isExecuting);
      isExecuting.subscribe(x => {
        ++count;

        if (count === 1) {
          // initial result
          x.should.eql(false);
        }
        else if (count === 2) {
          // executing
          x.should.eql(true);
        }
        else if (count === 3) {
          // reset after execution
          x.should.eql(false);

          done();
        }
      });

      cmd.execute();
    });
開發者ID:patsissons,項目名稱:rxobj,代碼行數:27,代碼來源:ReactiveCommand.spec.ts

示例2: it

    it('delays change notifications until disabled', (done) => {
      const prop = new ReactiveValueProperty(testOwner, 0);
      const subject = new BehaviorSubject<number>(0);

      prop.changed
        .map(x => x.value)
        .subscribe(subject);

      subject.value.should.eql(0);

      prop.value = 1;
      subject.value.should.eql(1);

      subject
        .subscribe(x => {
          if (x === 3) {
            done();
          }
        });

      Observable.using(
        () => prop.delayChangeNotifications(),
        x => {
          prop.value = 2;
          subject.value.should.eql(1);

          prop.value = 3;
          subject.value.should.eql(1);

          x.unsubscribe();
        }
      ).subscribe();
    });
開發者ID:patsissons,項目名稱:rxobj,代碼行數:33,代碼來源:ReactiveProperty.spec.ts

示例3: behaviorSubject

 behaviorSubject() {
     let behaviourSubject$ = new BehaviorSubject(-1); 
     interval(300).pipe(
         take(5)
     ).subscribe(behaviourSubject$);
     behaviourSubject$.subscribe(val => console.log(`First behaviour subject: ${val}`)); // -1, 0, 1, 2, 3, 4
     setTimeout(() => {
         behaviourSubject$.subscribe(val => console.log(`Second behaviour subject: ${val}`)); // 2, 3, 4
     }, 1000);
 }
開發者ID:mr-Deviant,項目名稱:sandbox,代碼行數:10,代碼來源:subjects.component.ts

示例4: it

it("value: For writeable observable values, should catch the node's onchange and write values back to the observable", async (t) => {
    const template = `<input type="text" x-value="someProp" />`;
    const el = parse(template)[0] as HTMLInputElement;

    const myobservable = new BehaviorSubject(123);
    ui.domManager.applyDirectives({ someProp: myobservable }, el);
    el.value = "some user-entered value";
    triggerEvent(el, "change");

    myobservable.subscribe((x) => {
        t.is(x.toString(), "some user-entered value");

    });

});
開發者ID:milutinovici,項目名稱:proactive,代碼行數:15,代碼來源:value-spec.ts

示例5: loader

  return function loader(name: string|SourceModel, req: any, onload: (param: any) => any) {
    const source: SourceModel = (typeof name === 'string' ? JSON.parse(name) : name);

    const subject = new BehaviorSubject<PouchDoc>(null);
    function update() {
      Observable.fromPromise(db.get(source.name)).subscribe(subject);
    }
    update();

    subject.subscribe(data => {
      console.log(data);
    });

    this.require([ source.src ], (src: Observable<any>) => {
      console.log(src);
      onload(Observable.of(1));
    });
  };
開發者ID:blmarket,項目名稱:simple-amd,代碼行數:18,代碼來源:cache-loader.ts

示例6: as

 () => {
   let output$: BehaviorSubject<T>
   if (inputs) {
     output$ = (inputFactory as (
       inputs$: Observable<U | undefined>,
       state$: Observable<T | undefined>,
     ) => Observable<T>)(inputs$, state$) as BehaviorSubject<T>
   } else {
     output$ = (inputFactory as (state$: Observable<T | undefined>) => Observable<T>)(state$) as BehaviorSubject<T>
   }
   const subscription = output$.subscribe((value) => {
     state$.next(value)
     setState(value)
   })
   return () => {
     subscription.unsubscribe()
     inputs$.complete()
     state$.complete()
   }
 },
開發者ID:morlay,項目名稱:rxjs-hooks,代碼行數:20,代碼來源:use-observable.ts

示例7: it

it("value: Should only notify observable properties on the model once even if the checkbox change events fire multiple times", async (t) => {
    const template = `<input type="checkbox" x-value="someProp" />`;
    const element = parse(template)[0] as HTMLInputElement;

    const myobservable = new BehaviorSubject(false);
    let timesNotified = 0;
    myobservable.subscribe(() => { timesNotified++; });
    timesNotified = 0; // ignore initial value notification
    ui.domManager.applyDirectives({ someProp: myobservable }, element);

    // Multiple events only cause one notification...
    triggerEvent(element, "click");
    triggerEvent(element, "change");
    triggerEvent(element, "change");
    t.is(timesNotified, 1);

    // ... until the checkbox value actually changes
    triggerEvent(element, "click");
    triggerEvent(element, "change");
    t.is(timesNotified, 2);

});
開發者ID:milutinovici,項目名稱:proactive,代碼行數:22,代碼來源:checked-spec.ts

示例8: resolve

                () => {
                    if ( this.routeParams.todoId )
                    {
                        this.setCurrentTodo(this.routeParams.todoId);
                    }
                    else
                    {
                        this.setCurrentTodo(null);
                    }

                    this.onSearchTextChanged.subscribe(searchText => {
                        if ( searchText !== '' )
                        {
                            this.searchText = searchText;
                            this.getTodos();
                        }
                        else
                        {
                            this.searchText = searchText;
                            this.getTodos();
                        }
                    });
                    resolve();
                },
開發者ID:karthik12ui,項目名稱:fuse-angular-full,代碼行數:24,代碼來源:todo.service.ts

示例9: reducer

import * as WeatherForecasts from './WeatherForecasts';
import * as Counter from './Counter';


// The top-level state object interface
export interface IApplicationState {
    counter: Counter.ICounterState,
    weatherForecasts: WeatherForecasts.WeatherForecastsState
}

const initialState: IApplicationState = { counter: { count: 0 }, weatherForecasts: { isLoading: false, startDateIndex: 0, forecasts: [] } }

// STORE The top-level state object 
export const Store = new Rx.BehaviorSubject<IApplicationState>(initialState);

const scopedReducers = {
    counter: Counter.CounterReducer,
    weatherForecasts: WeatherForecasts.CounterReducer
}

const reducers = Object.keys(scopedReducers)
    .filter(key => scopedReducers[key] instanceof Rx.Observable && typeof Store.getValue()[key] !== "undefined")
    .map(key => scopedReducers[key].map(reducer => (state: IApplicationState): IApplicationState => (Object.assign({}, state, { [key]: reducer(state[key]) } ))));

Rx.Observable.merge(...reducers)
    .scan((state: IApplicationState, reducer) => reducer(state), Store.getValue())
    .subscribe(Store);

// DEBUG
Store.subscribe(console.log);
開發者ID:vobradovich,項目名稱:aspnetcore-spa-rxjs,代碼行數:30,代碼來源:Store.ts


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