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);
          })
        })
      }
  • 相关阅读:
    逛画展
    数的划分
    有点难度的树链刨分
    树链刨分
    记502 dp专练
    数论相关
    模拟退火
    仓鼠找sugar
    NOIP 2017 解题报告
    整体二分
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6597625.html
Copyright © 2011-2022 走看看