• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.unionBy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中lodash.unionBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript unionBy函数的具体用法?TypeScript unionBy怎么用?TypeScript unionBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了unionBy函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: updateInventory

export function updateInventory(
  inventory: Inventory, itemName: ItemName, amount: number, maxAmount = amount
): Inventory {
  let newStack;

  if (hasItem(inventory, itemName)) {
    const itemStack = getItem(inventory, itemName);

    newStack = _.cloneDeep(itemStack);

    Item.changeStackAmount(newStack, amount);
  } else {
    const isFull = inventoryIsFull(inventory);
    if (!isFull && amount > 0) {
      newStack = Item.createItemStack(createItem(itemName), amount, maxAmount);
    } else if (isFull && amount > 0) {
      throw new Error(
        'Attempted to add a non-present item to a full inventory!'
      );
    } else {
      // amount <= 0
      throw new Error(
        'Attempted to update an inventory with a non-present item with a non-positive amount!'
      );
    }
  }

  const newItemStacks = Item.removeEmptyStacks(_.unionBy([ newStack ], inventory.itemStacks, 'item.name'));

  return {
    itemStacks: newItemStacks,
    maximumCapacity: inventory.maximumCapacity
  };
}
开发者ID:zthomae,项目名称:xanadu,代码行数:34,代码来源:inventory.ts


示例2: default

export default (state: RangeState = initialState, action: Action) => {
  switch (action.type) {
    case ActionTypes.DeleteTimeRange: {
      const {dashboardID} = action.payload
      const ranges = state.filter(r => r.dashboardID !== dashboardID)

      return ranges
    }

    case ActionTypes.RetainRangesDashboardTimeV1: {
      const {dashboardIDs} = action.payload
      const ranges = state.filter(r => dashboardIDs.includes(r.dashboardID))
      return ranges
    }

    case ActionTypes.SetDashboardTimeV1: {
      const {dashboardID, timeRange} = action.payload
      const newTimeRange = [{dashboardID, ...timeRange}]
      const ranges = _.unionBy(newTimeRange, state, 'dashboardID')

      return ranges
    }
  }

  return state
}
开发者ID:viccom,项目名称:influxdb,代码行数:26,代码来源:ranges.ts


示例3:

    ]).then(function (resultArray) {
      that.NotificationService.show("Tenants saved with success");
//      that.loadTenants();
      that.tenantsToCreate = [];
      that.tenantsToUpdate = [];
      let createResult = resultArray[0];
      if (createResult) {
        that.tenants = _.unionBy(createResult.data, that.tenants, 'name');
      }
    });
开发者ID:gravitee-io,项目名称:gravitee-management-webui,代码行数:10,代码来源:tenants.controller.ts


示例4: experiment

  /* この仕組みを使って差分だけデータを取得する関数を作る */
  experiment() {
    let a = [{ key: 'x', timestamp: '100' }];
    let b = [{ key: 'x', timestamp: '200' }];
    let c = lodash.union(a, b); // 2つの配列を1つにまとめる。
    console.log(c); // [{ key: 'x', timestamp: '100' }, { key: 'x', timestamp: '200' }]

    let d = lodash.unionBy(a, b, 'key'); // 2つの配列を1つにまとめ、同一キーのオブジェクトは左にあるものが生きる。(この場合はa)
    console.log(d); // [{ key: 'x', timestamp: '100' }]

    let e = lodash.unionBy(b, a, 'key'); // 2つの配列を1つにまとめ、同一キーのオブジェクトは左にあるものが生きる。(この場合はb)
    console.log(e); // [{ key: 'x', timestamp: '200' }]

    let f = [{ key: 'x', timestamp: '100' }, { key: 'x', timestamp: '200' }];
    let g = lodash.uniqBy(f, 'key'); // 同一キーのオブジェクトは左にあるものが生きる。
    console.log(g); // [{ key: 'x', timestamp: '100' }]

    let h = [{ key: 'x', timestamp: '200' }, { key: 'x', timestap: '100' }];
    let i = lodash.uniqBy(h, 'key');
    console.log(i); // [{ key: 'x', timestamp: '200' }]
  }
开发者ID:ovrmrw,项目名称:jspm-angular2-sample,代码行数:21,代码来源:note-list.service.ts


示例5: stethoscope

  // TODO: Refactor out logging logic into seperate file
  async function stethoscope() {
    try {
      const currentTab = await getCurrentTab();
      const currentTabArray = (await isTabActive(currentTab))
        ? [currentTab]
        : [];
      const audibleTabs = await browser.tabs.query({ audible: true });
      const tabs = filter(
        unionBy(currentTabArray, audibleTabs, 'url'),
        tab => !tab.incognito
      );

      const timeSinceLastPoll = pollTimer();
      if (timeSinceLastPoll > 70) {
        // If significantly more than 60s, reset timers.
        // This is usually indicative of computer being suspended.
        // See: https://github.com/SuperuserLabs/thankful/issues/61
        console.log('suspend detected, resetting timers');
        each(tabTimers, tabTimer => tabTimer());
      }

      const currentUrls = tabs.map(tab => canonicalizeUrl(tab.url));
      const goneUrls = difference(Object.keys(tabTimers), currentUrls);
      const stillUrls = intersection(Object.keys(tabTimers), currentUrls);
      const newUrls = difference(currentUrls, Object.keys(tabTimers));

      goneUrls.forEach(url => {
        const duration = tabTimers[url]();
        const title = tabTitles[url];
        delete tabTimers[url];
        delete tabTitles[url];
        db.logActivity(url, duration, { title: title });
      });
      stillUrls.forEach(url => {
        const duration = tabTimers[url]();
        let title = find(tabs, tab => canonicalizeUrl(tab.url) === url).title;
        tabTitles[url] = title;
        db.logActivity(url, duration, { title: title });
      });
      newUrls.forEach(url => {
        tabTimers[url] = valueConstantTicker();
        tabTimers[url]();
        tabTitles[url] = find(
          tabs,
          tab => canonicalizeUrl(tab.url) === url
        ).title;
      });
      await rescheduleAlarm();
    } catch (error) {
      console.log(`Stethoscope error: ${error}`);
    }
  }
开发者ID:ActivityWatch,项目名称:thankful,代码行数:53,代码来源:background.ts


示例6: produce

  return produce(state, draftState => {
    switch (action.type) {
      case ActionTypes.SetDashboards: {
        const {list, status} = action.payload

        draftState.status = status
        if (list) {
          draftState.list = list
        }

        return
      }

      case ActionTypes.RemoveDashboard: {
        const {id} = action.payload
        draftState.list = draftState.list.filter(l => l.id !== id)

        return
      }

      case ActionTypes.SetDashboard: {
        const {dashboard} = action.payload
        draftState.list = _.unionBy([dashboard], state.list, 'id')

        return
      }

      case ActionTypes.EditDashboard: {
        const {dashboard} = action.payload

        draftState.list = draftState.list.map(d => {
          if (d.id === dashboard.id) {
            return dashboard
          }
          return d
        })

        return
      }

      case ActionTypes.RemoveCell: {
        const {dashboard, cell} = action.payload
        draftState.list = draftState.list.map(d => {
          if (d.id === dashboard.id) {
            const cells = d.cells.filter(c => c.id !== cell.id)
            d.cells = cells
          }

          return d
        })

        return
      }

      case ActionTypes.AddDashboardLabels: {
        const {dashboardID, labels} = action.payload

        draftState.list = draftState.list.map(d => {
          if (d.id === dashboardID) {
            d.labels = [...d.labels, ...labels]
          }

          return d
        })

        return
      }

      case ActionTypes.RemoveDashboardLabels: {
        const {dashboardID, labels} = action.payload
        draftState.list = draftState.list.map(d => {
          if (d.id === dashboardID) {
            const updatedLabels = d.labels.filter(el => {
              const labelToRemove = labels.find(l => l.id === el.id)

              return !labelToRemove
            })

            d.labels = updatedLabels
          }

          return d
        })

        return
      }
    }
  })
开发者ID:influxdata,项目名称:influxdb,代码行数:88,代码来源:dashboards.ts


示例7: default

export default (state: State = [], action: Action): State => {
  switch (action.type) {
    case ActionTypes.LoadDashboards: {
      const {dashboards} = action.payload

      return [...dashboards]
    }

    case ActionTypes.DeleteDashboard: {
      const {dashboardID} = action.payload

      return [...state.filter(d => d.id !== dashboardID)]
    }

    case ActionTypes.LoadDashboard: {
      const {dashboard} = action.payload

      const newDashboards = _.unionBy([dashboard], state, 'id')

      return newDashboards
    }

    case ActionTypes.UpdateDashboard: {
      const {dashboard} = action.payload
      const newState = state.map(
        d => (d.id === dashboard.id ? {...dashboard} : d)
      )

      return [...newState]
    }

    case ActionTypes.DeleteCell: {
      const {dashboard, cell} = action.payload
      const newState = state.map(d => {
        if (d.id !== dashboard.id) {
          return {...d}
        }

        const cells = d.cells.filter(c => c.id !== cell.id)
        return {...d, cells}
      })

      return [...newState]
    }

    case ActionTypes.AddDashboardLabels: {
      const {dashboardID, labels} = action.payload

      const newState = state.map(d => {
        if (d.id === dashboardID) {
          return {...d, labels: [...d.labels, ...labels]}
        }
        return d
      })

      return [...newState]
    }

    case ActionTypes.RemoveDashboardLabels: {
      const {dashboardID, labels} = action.payload

      const newState = state.map(d => {
        if (d.id === dashboardID) {
          const updatedLabels = d.labels.filter(l => {
            return !labels.includes(l)
          })
          return {...d, labels: updatedLabels}
        }
        return d
      })

      return [...newState]
    }
  }

  return state
}
开发者ID:viccom,项目名称:influxdb,代码行数:77,代码来源:dashboards.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.uniq函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.union函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap