本文整理汇总了TypeScript中rxjs/Observable.Observable.combineLatest方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.combineLatest方法的具体用法?TypeScript Observable.combineLatest怎么用?TypeScript Observable.combineLatest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Observable.Observable
的用法示例。
在下文中一共展示了Observable.combineLatest方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: initObservable
export function initObservable() {
const click$ = Observable.fromEvent(document,'click');
const mouse$ = Observable.fromEvent(document,'mousemove')
.filter((move:MouseEvent) => move.clientY >=200);
const combined$ = Observable.combineLatest(mouse$, click$);
combined$.subscribe(
combined => console.log(combined[0])
);
}
示例2: constructor
constructor(
private store: Store<any>
){
this.viewModel$ = Observable.combineLatest(
store.select('todos'),
store.select('visibilityFilter'),
({past = [], present = [], future = []}, visibilityFilter : string) => {
return {
todos: this.visibleTodos(present, visibilityFilter),
totalTodos: present.length,
completedTodos: present.filter((todo : Todo) => todo.completed).length
}
}
);
}
示例3: constructor
constructor(
private store: Store<any>
){
this.viewModel$ = Observable.combineLatest(
store.select('todos'),
store.select('visibilityFilter'),
(todos : Array<Todo>, visibilityFilter : string) => {
return {
todos: this.visibleTodos(todos, visibilityFilter),
totalTodos: todos.length,
completedTodos: todos.filter((todo : Todo) => todo.completed).length
}
}
);
}
示例4: typeahead
export function typeahead(element: ElementRef, minLength = 1, debounceTime = 250): Observable<string> {
return Observable.combineLatest(
Observable.merge(
Observable.fromEvent(element.nativeElement, 'compositionstart').map(() => true),
Observable.fromEvent(element.nativeElement, 'compositionend').map(() => false),
).startWith(false),
Observable.fromEvent(element.nativeElement, 'keyup'),
)
.filter(array => !array[0])
.map(array => array[1])
.map((event: KeyboardEvent) => (event.target as HTMLInputElement).value)
.debounceTime(debounceTime)
.distinctUntilChanged()
.filter(value => value.length >= minLength);
}
示例5: constructor
constructor(
private store: Store<any>
) {
this.viewModel$ = Observable.combineLatest(
store.select('games'),
store.select('visibilityFilter'),
(games: Array<IGame>, visibilityFilter: string) => {
return {
games: this.visibleGames(games, visibilityFilter),
totalGames: games.length,
completedGames: games.filter((game: Game) => game.completed).length
}
}
);
}
示例6: ngOnInit
ngOnInit() {
Observable.combineLatest([
this.route.paramMap,
this.route.queryParamMap
])
.switchMap(combined => {
let id = combined[0].get('id');
let page = combined[1].get('page');
return this.service.getAll();
})
.subscribe(followers => this.followers = followers);
}
示例7: function
/**
* compute ratio
*/
export default function(options: ResponsiveOptions) {
const scaleSubject = new BehaviorSubject<any>(true);
const scaleFn = compose(centeringOf(options.target), scalingOf(options.target));
const hRatio = scaleSubject.map(horizontalRatioOf(options.width));
const vRatio = scaleSubject.map(verticalRatioOf(options.height));
const currentRatio = Observable.combineLatest(hRatio, vRatio).map((hv) => Math.min(hv[0], hv[1]));
currentRatio.subscribe(scaleFn);
return {
scale : scaleSubject,
currentRatio : currentRatio
};
}
示例8: Date
.subscribe(data => {
// map source format to time series data
let mapped = data.map(single => {
let typed:TimeSeriesData = {
value : single[1],
date : new Date(single[0])
}
return typed;
});
// store data
this.data = mapped;
// DEBUG - we could map the data to percentual changes to the last quarter and offer this as another option...
// let change = this.data.map(d => d.value).map((value, index, array) => index == 0 ? 0 : value / array[index-1] - 1);
// console.warn(change);
// store all years for which we have data
this.years = this.data
.map(tsd => tsd.date.getUTCFullYear())
.filter((elem, pos, arr) => arr.indexOf(elem) == pos);
// ensure that from <= to in all cases
this.yearFrom.valueChanges.subscribe(newFrom => {
if (this.yearTo.value < newFrom)
this.yearTo.updateValue(newFrom);
});
this.yearTo.valueChanges.subscribe(newTo => {
if (this.yearFrom.value > newTo)
this.yearFrom.updateValue(newTo);
});
// whenever one of the years (from,to) change, update the filtered data
Observable.combineLatest(this.yearFrom.valueChanges, this.yearTo.valueChanges)
.debounceTime(50)
.subscribe(yearRange => {
let from:number = yearRange[0];
let to:number = yearRange[1];
this.filteredData = this.data.filter(dataPoint => dataPoint.date.getUTCFullYear() >= from && dataPoint.date.getUTCFullYear() <= to);
});
// set initial values to first and last available year
this.showAllData();
});
示例9: getCantonOptions
getCantonOptions(): Observable<IMultiSelectOption[]> {
const mapToOption = (key: string) => ({
id: key,
name: `global.reference.canton.${key}`
});
const translateOption = (option: IMultiSelectOption) => {
return this.translateService.stream(option.name)
.map((translation) => Object.assign({}, option, { name: translation }));
};
const translatedOptions = Object.keys(Canton)
.filter((key) => !isNaN(Number(Canton[key])))
.map(mapToOption)
.map(translateOption);
return Observable.combineLatest(translatedOptions);
}
示例10: it
it('should work', () => {
const subjectA = new Subject<string>();
const subjectB = new Subject<string>();
const log: string[] = [];
const subject = Observable.combineLatest(subjectA, subjectB).subscribe(([a, b]) => {
log.push(`${a}-${b}`);
});
subjectA.next('hello');
expect(log).toEqual([]);
subjectB.next('world');
expect(log).toEqual(['hello-world']);
subjectA.next('bye');
expect(log).toEqual(['hello-world', 'bye-world']);
});