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


TypeScript lodash.differenceBy函数代码示例

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


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

示例1: renderPins

export function* renderPins() {
	try {
		const filteredIssues = yield select(selectFilteredIssues);
		const issuesList = yield select(selectIssues);
		const shouldShowPins = yield select(selectShowPins);
		const invisibleIssues = issuesList.length !== filteredIssues.length
			? differenceBy(issuesList, filteredIssues, '_id')
			: [];

		const activeIssueId = yield select(selectActiveIssueId);
		const removePins = (issues) => issues.forEach((issue) => {
			Viewer.removePin({ id: issue._id });
		});

		yield removePins(!shouldShowPins ? issuesList : invisibleIssues);

		if (shouldShowPins) {
			for (let index = 0; index < filteredIssues.length; index++) {
				const issue = filteredIssues[index];

				const pinPosition = issue.position && issue.position.length;

				if (pinPosition) {
					const isSelectedPin = activeIssueId && issue._id === activeIssueId;
					const pinColor = isSelectedPin ? PIN_COLORS.YELLOW : PIN_COLORS.BLUE;

					Viewer.addPin({
						id: issue._id,
						type: 'issue',
						account: issue.account,
						model: issue.model,
						pickedPos: issue.position,
						pickedNorm: issue.norm,
						colours: pinColor,
						viewpoint: issue.viewpoint
					});
				}
			}
		}

		yield Viewer.removePin({ id: NEW_PIN_ID });
	} catch (error) {
		yield put(DialogActions.showErrorDialog('show', 'pins', error));
	}
}
开发者ID:3drepo,项目名称:3drepo.io,代码行数:45,代码来源:issues.sagas.ts

示例2: renderPins

export function* renderPins() {
	try {
		const filteredRisks = yield select(selectFilteredRisks);
		const risksList = yield select(selectRisks);
		const shouldShowPins = yield select(selectShowPins);
		const invisibleRisks = risksList.length !== filteredRisks.length
			? differenceBy(risksList, filteredRisks, '_id')
			: [] ;

		const activeRiskId = yield select(selectActiveRiskId);
		const removePins = (risks) => risks.forEach((risk) => {
			Viewer.removePin({ id: risk._id });
		});

		yield Viewer.removePin({ id: NEW_PIN_ID });
		yield removePins(!shouldShowPins ? risksList : invisibleRisks);

		if (shouldShowPins) {
			for (let index = 0; index < filteredRisks.length; index++) {
				const risk = filteredRisks[index];

				const pinPosition = risk.position && risk.position.length;

				if (pinPosition) {
					const levelOfRisk = (risk.overall_level_of_risk !== undefined) ? risk.overall_level_of_risk : 4;
					const isSelectedPin = activeRiskId && risk._id === activeRiskId;
					const pinColor = getRiskPinColor(levelOfRisk, isSelectedPin);
					Viewer.addPin({
						id: risk._id,
						type: 'risk',
						account: risk.account,
						model: risk.model,
						pickedPos: risk.position,
						pickedNorm: risk.norm,
						colours: pinColor,
						viewpoint: risk.viewpoint
					});
				}
			}
		}
	} catch (error) {
		yield put(DialogActions.showErrorDialog('show', 'pins', error));
	}
}
开发者ID:3drepo,项目名称:3drepo.io,代码行数:44,代码来源:risks.sagas.ts

示例3: upsertOption

import { Context, getShopId } from '../../utils';
import * as _ from 'lodash';

export const option = {
  async upsertOption(parent, args, ctx: Context, info) {
    if (args.optionId) {
      const currentOption = await ctx.db.query.option({ where: { id: args.optionId } }, info);

    const optionValuesToDelete = _.differenceBy(currentOption.values, args.values, 'id');
    const optionValuesToDeleteInput = optionValuesToDelete.map(optionValue => ({ id: optionValue.id }))

    const optionValuesToCreate = _(args.values)
      .differenceBy(currentOption.values, 'id')
      .map((optionValue: any) => ({ name: optionValue.value }))
      .value();

    const optionValuesToUpdate = args.values
    .filter(optionValue =>
      !!currentOption.values.find((currentOptionValue) => currentOptionValue.id === optionValue.id)
    )
    .map(optionValue => ({
      where: { id: optionValue.id },
      data: { name: optionValue.value }
    }));

      // Some option values were deleted
      if (args.values.length < currentOption.values.length) {
        // Find all variants that had one of the removed option value
        const variantsToDelete = await Promise.all(
          optionValuesToDelete.map((optionValueToDelete) => (
            ctx.db.query.variants({
开发者ID:Coder108,项目名称:prisma-ecommerce,代码行数:31,代码来源:option.ts

示例4: OrderNotFoundException

    if (!order) {
      throw new OrderNotFoundException();
    }

    // Add to the cart only the lineItems that have a product that still exists
    const existingProducts = await Promise.all(
      order.lineItems.map(lineItem => ctx.db.exists.Product({ id: lineItem.variant.product.id, deletedAt: null }))
    );
    const lineItemsWithExistingProduct = order.lineItems.filter((_, i) => existingProducts[i]);

    const currentCart = await ctx.db.query.user({ where: { id: userId } }, `{ cart { id quantity variant { id } } }`).then(user => user.cart);

    // Delete all items from cart that are not in the order
    if (args.replace) {
      const cartLineItemsToDelete = _.differenceBy(currentCart, lineItemsWithExistingProduct, (lineItem) => lineItem.variant.id);

      await Promise.all(
        cartLineItemsToDelete.map(lineItem => ctx.db.mutation.deleteOrderLineItem({ where: { id: lineItem.id } }))
      );
    }

    return await Promise.all(
      lineItemsWithExistingProduct.map(orderLineItem => {
        const cartOrderLineItem = currentCart.find(cartLineItem => cartLineItem.variant.id === orderLineItem.variant.id);

        if (cartOrderLineItem) {
          return ctx.db.mutation.updateOrderLineItem({
            where: { id: cartOrderLineItem.id },
            data: {
              quantity: args.replace
开发者ID:Coder108,项目名称:prisma-ecommerce,代码行数:30,代码来源:cart.ts

示例5: Date

        { where: { id: args.productId } },
        `{
          id
          attributes { id }
          options { id }
          variants { id }
          unavailableOptionsValues { id }
        }`
      );

      // 1. If some variants were removed (eg: an option value were unselected from the product)
      // 2. Soft-delete the variants, their associated selectedOptions, and the orderLineItems that had those variants
      // Remark: Ideally, we should only soft-delete the variants that are in orders, and hard-delete the others, but we make it easier this way
      // Remark: We don't disconnect the variants from the product so that users can still see the items that were deleted from their cart.
      // Remark: Because of that, we need to filter the soft_deleted variants everywhere else. :(
      const variantsToDelete = _.differenceBy(currentProduct.variants, args.variants, 'id');

      if (variantsToDelete.length > 0) {
        const variantsIdsToDelete = variantsToDelete.map(variant => variant.id);
        const deletedAt = new Date().toISOString();
      
        await ctx.db.mutation.updateManySelectedOptions({
          where: {
            variant: {
              id_in: variantsIdsToDelete,
              product: { id: args.productId } }
          },
          data: { deletedAt }
        });

        await ctx.db.mutation.updateManyVariants({
开发者ID:Coder108,项目名称:prisma-ecommerce,代码行数:31,代码来源:product.ts

示例6: _

        position: bestSellerProduct.position
      }));

    const currentShop = await ctx.db.query.shop({ where: { id: shopId } }, `
      {
        bestSellerProducts {
          id
          product { id }
        }
      }`);

    const productsToDelete = _(currentShop.bestSellerProducts)
      .differenceBy(args.bestSellerProducts, 'id')
      .map(orderableProduct => ({ id: orderableProduct.id }))
      .value();
    const productsToConnect = _.differenceBy(args.bestSellerProducts, currentShop.bestSellerProducts, 'id')
    const productsToUpdate = args.bestSellerProducts
      .filter((orderableProduct: OrderableProductInput) =>
        !!currentShop.bestSellerProducts.find((currentProduct) => currentProduct.id === orderableProduct.id)
      )
      .map((orderableProduct: OrderableProductInput) => ({
        where: { id: orderableProduct.id },
        data: { position: orderableProduct.position }
      }));

    return ctx.db.mutation.updateShop({
      where: { id: shopId },
      data: {
        bestSellerProducts: {
          create: buildCreateInput(productsToConnect),
          delete: productsToDelete,
开发者ID:Coder108,项目名称:prisma-ecommerce,代码行数:31,代码来源:shopMetadata.ts


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