当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.combineLatest方法代码示例

本文整理汇总了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])
    );
}
开发者ID:frozentp,项目名称:courses,代码行数:14,代码来源:init-observable.ts

示例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
             }
         }
     );
 }
开发者ID:Hongbo-Miao,项目名称:ngrx-examples,代码行数:15,代码来源:todos-viewmodel.ts

示例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
             }
         }
     );
 }
开发者ID:justdaft,项目名称:ngrx-examples,代码行数:15,代码来源:todos-viewmodel.ts

示例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);
}
开发者ID:Gitjerryzhong,项目名称:bell-tm-static,代码行数:15,代码来源:typeahead.ts

示例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
       }
     }
     );
 }
开发者ID:justdaft,项目名称:super-duper-guacamole,代码行数:15,代码来源:todos-viewmodel.ts

示例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);
  
      
    }
开发者ID:krzysztofkarp,项目名称:udemy-angular,代码行数:16,代码来源:github-followers.component.ts

示例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
  };
}
开发者ID:1000ch,项目名称:Talkie,代码行数:19,代码来源:responsive.ts

示例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();
      });
开发者ID:thorstenschaefer,项目名称:d3-playground,代码行数:47,代码来源:gdp.component.ts

示例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);
    }
开发者ID:alv-ch,项目名称:job-room,代码行数:17,代码来源:canton.service.ts

示例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']);
    });
开发者ID:loki2302,项目名称:html5-experiment,代码行数:17,代码来源:rxjs.spec.ts


注:本文中的rxjs/Observable.Observable.combineLatest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。