本文整理匯總了TypeScript中rxjs/Rx.Observable.combineLatest方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.combineLatest方法的具體用法?TypeScript Observable.combineLatest怎麽用?TypeScript Observable.combineLatest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.combineLatest方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: waitForTxnDetailDataToLoad
waitForTxnDetailDataToLoad(): Observable<any> {
this.txnDetail$ = Observable.combineLatest(
this.store.select(fromRoot.getCustomerDetails),
this.store.select(fromRoot.getLoggedInUser),
this.store.select(fromRoot.getDetailTransaction),
this.store.select(fromRoot.getSelectedpropertyName),
(custDtls, loggedInUser, txnDtl, propertyName) => {
var businessInfo = {firstName:loggedInUser.firstName,
lastName:loggedInUser.lastName,
email:loggedInUser.email,
phoneNumber: (undefined != loggedInUser.phoneNum)?loggedInUser.phoneNum:'Not Provided',
faxNumber:(undefined != loggedInUser.faxNum)?loggedInUser.faxNum:'Not Provided',
addr: custDtls.contactAddress,
fedTaxId:(undefined != custDtls.fedTaxId)?custDtls.fedTaxId:'Not Provided',
languagePref:custDtls.correspondenceLang
}
return {businessInfo,txnDtl,propertyName}
});
return new Observable(observer => {
this.txnDetail$.subscribe(dtl => {
if(dtl.txnDtl.isLoadingSuccess){
observer.next(dtl);
observer.complete();
}
})
});
}
示例2: constructor
constructor(public store: Store<any[]>) {
this.filteredTodos = Observable.combineLatest(store.select('todos'), store.select('visibility'), (todos: any, visibilityFilter: any) => todos.filter(visibilityFilter.filter));
this.todos = store.select('todos');
this.visibilityFilter = store.select('visibility');
this.completedCount = this.todos.map((todos: any) => todos.reduce((count, todo) => todo.completed ? count + 1 : count, 0));
this.activeCount = this.todos.map((todos: any) => todos.length - (todos.reduce((count, todo) => todo.completed ? count + 1 : count, 0)));
}
示例3: setTimeout
return new Promise<void>(resolve => {
let timer;
if (typeof timeout === 'number' && timeout > 0) {
timer = setTimeout(() => {
console.warn(chalk.yellow(`Timed out while waiting for NgZone to become stable after ${timeout}ms! This is a serious performance problem!`));
console.warn(chalk.yellow('This likely means that your application is stuck in an endless loop of change detection or some other pattern of misbehaviour'));
console.warn(chalk.yellow('In a normal application, a zone becomes stable very quickly'));
console.warn('Proceeding with render operation even though the zone is not stable: this is a very dangerous thing to do!')
console.warn('You can adjust the zone-becomes-stable timeout with ApplicationBuilder::stabilizeTimeout(), or zero to disable');
resolve();
},
timeout);
}
const combined = Observable.combineLatest(applicationRef.isStable, requests.requestsPending(),
(appStable, pending) => {
return appStable && pending === 0;
});
const subscription = combined.subscribe(v => {
if (v === true) {
if (subscription) {
subscription.unsubscribe();
}
if (timer != null) {
clearTimeout(timer);
}
resolve();
}
});
});
示例4: expect
constructorZone3.run(() => {
combinedObservable =
Rx.Observable.combineLatest(observable1, observable2, (x: number, y: number) => {
expect(Zone.current.name).toEqual(constructorZone3.name);
return x + y;
});
});
示例5: constructor
//TODO: create as a computed store service:
// http://onehungrymind.com/handle-multiple-angular-2-models-ngrx-computed-observables/
constructor(private _store: Store<AppState> /*, private _itemService: TripService*/) {
this.searchTab = new Tab();
this.searchTab.id = 'tab-id-search';
this.searchTab.title = 'Search';
this.searchTab.template = 'search';
this.searchTab.active = true;
this.searchTab.closeable = false;
this.searchTab.itemId = '';
this.activeTabId$ = _store.select(x => x.trip.activeTabId);
this.openItems$ = _store.select(x => x.trip.openList);
this.tabs$ = this.openItems$
.combineLatest(this.activeTabId$)
.map(([trips, activeId]) => {
this.searchTab.active = activeId === this.searchTab.id || !activeId;
return [this.searchTab].concat(trips.map(item => {
let exists = item.Trip && item.Trip.TripId && item.Trip.TripId.length > 0;
let t = new Tab();
t.id = item.PlaceholderId;
t.title = exists ? item.Trip.DepartDate : 'Add Trip'; //TODO: what is a good title here??
t.template = 'item';
t.active = activeId === t.id;
t.closeable = true;
t.item = item;
t.itemId = item.Trip.TripId;
return t;
}));
});
}
示例6: todoItemDataFlow
export function todoItemDataFlow(intent: TodoItemIntent, todoProperty$: Observable<Todo>){
const editing$ = Observable.merge<boolean, boolean>(
intent.startEdit$.map(() => true),
intent.stopEdit$.map(() => false),
intent.cancelEdit$.map(() => false)
).startWith(false);
const viewModel$ = todoProperty$
.combineLatest(editing$, (todoProperty, editing) => Object.assign({}, todoProperty, { editing }));
const delete$ = intent.delete$
.withLatestFrom(todoProperty$, (_, todo: Todo) => todo)
.map(x => ({ id: x.id }));
const edit$ = intent.stopEdit$
.withLatestFrom(todoProperty$, (title: string, todo: Todo) => ({ title, todo }))
.filter(x => x.title !== x.todo.title)
.map(x => ({ id: x.todo.id, title: x.title }));
const toggle$ = intent.toggleTodo$
.withLatestFrom(todoProperty$, (_, todo: Todo) => todo)
.map(todo => ({ id: todo.id }));
return {
viewModel$,
delete$,
edit$,
toggle$
};
}
示例7: matchItemsIntervalToTimer
export const compileTickObservable = (items$, stop$, start$) => {
/**
* Observable stream that emits the number of ms passed since it's started at interval of minInterval
*/
const timer$ = Observable.interval(minInterval)
.map(val => val * minInterval);
/**
* This observable combines both the timer stream and the stream injected from the store (which contains the items)
* Outputs the items whose interval match the time
*/
const matchedItems$ = Observable.combineLatest(
items$,
timer$,
(items, timer) => ({items: items, timer: timer}) // mapping for combineLatest as last param
)
.takeUntil(stop$) // stop the stream when receiving incoming from the stop$ stream (a click)
.filter(data => {
return matchItemsIntervalToTimer(data.items, data.timer).length; // filter the timers without any matches
})
.distinct((previousData, nextData) => previousData.timer === nextData.timer) // make sure we dont emit twice the same timer
.map(data => ({items: matchItemsIntervalToTimer(data.items, data.timer), timer: data.timer })); // only return the matches for this time
// we return a stream that will start when start$ receives incomming
return start$
.startWith({}) // start automatically the stream when incomming data at init
.switchMapTo(matchedItems$); // simply pass the logic above
};
示例8: it
it("should not cause the command to be executed twice when the condition changes during execution", (done) => {
class MyInnerClass extends ReactiveObject {
constructor() {
super();
this.prop = "";
}
public get prop(): string {
return this.get("prop");
}
public set prop(val: string) {
this.set("prop", val);
}
}
class MyClass extends ReactiveObject {
constructor() {
super();
this.value = new MyInnerClass();
}
public get value(): MyInnerClass {
var val = this.get("value");
if (!val) {
val = new MyInnerClass();
this.value = val;
}
return val;
}
public set value(val: MyInnerClass) {
this.set("value", val);
}
}
var obj: MyClass = new MyClass();
var innerCommand = ReactiveCommand.create((a) => {
return obj.value.prop;
});
var isValid = obj.whenAnyValue(vm => vm.value.prop).map(c => {
return !!c.trim();
});
var canExecute = Observable.combineLatest(
isValid,
innerCommand.isExecuting.map(ie => !ie),
(valid, notRunning) => {
return valid && notRunning
}
)
var count: number = 0;
var command: ReactiveCommand<any, any> = ReactiveCommand.createFromObservable((a) => {
count++;
obj.value = new MyInnerClass();
return innerCommand.execute();
}, canExecute);
obj.value.prop = "Custom";
command.execute().subscribe(() => {
expect(count).to.equal(1);
}, err => done(err), () => done());
});
示例9: onSubmit
onSubmit(value: any): void {
var self : ThreadDetailComponent = this;
var id : string;
Observable.combineLatest<string,string>(
this._routeParams.switchMap((params: Params) => (id = params['id'])),
this.rService.observeServicesLink('threads')
).flatMap<Response>(([id,link], index) => this.rService.post('posts', {thread:link+'/'+id, body:value['message']})
).flatMap(response=>this.rService.observeService('threads', '/'+id+'/posts')
).take(1).subscribe(response=>{self.data['posts']=response.json()._embedded['posts'];self.postForm.reset();}
,error=>console.log(error));
}
示例10: constructor
constructor(private store: Store<fromRoot.State>, private formsService: FormsService, private appConfig: AppConfigService) {
this.initSubs = Observable.combineLatest(
store.select(fromRoot.getRelationshipIdForStartStopTxn),
store.select(fromRoot.getSelectedPropertyBPType)
).subscribe((result: any) => {
this.relationshipId = result[0];
this.bpType = result[1];
})
this.downloadRestUrl = this.appConfig.readEnvironment('downloadRestUrl');
}