當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。