本文整理匯總了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();
});
示例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();
});
示例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);
}
示例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");
});
});
示例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));
});
};
示例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()
}
},
示例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);
});
示例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();
},
示例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);