zoukankan      html  css  js  c++  java
  • [RxJSv& Javascript] forkJoin (reactive Promise.all) & Map

    forkJoin: When all observables complete emit the last value from each.

    productMap: Map<number, IProduct>
    
      ngOnInit() {
        const cart = this.stockService.getCartItems();
        const products = this.stockService.getProducts();
    
        Observable.forkJoin(
          cart,
          products
        ).subscribe(([cart, products]: [Item[], IProduct[]]) => {
          const myMap = products.map<[number, IProduct]>((p) => {
            return [p.id, p];  //[0, obj]
          });
          this.productMap = new Map<number, IProduct>(myMap); // {0: obj}
          this.products = products;
    
          cart.forEach((c) => {
            this.addStock(c);
          })
        })
      }
  • 相关阅读:
    JavaScript
    多线程
    MySQL进阶一(基础查询)
    英语语法随笔1
    MySQL
    Love Story
    两个数组的交集
    只出现一次的数字
    MybatisPlus
    数组中值加一
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6597625.html
Copyright © 2011-2022 走看看