function productVariationUpdated( state, action ) {
	const { data: productVariation, productId } = action;
	const productVariations = state.productVariations || [];
	const index = findIndex( productVariations, { id: productVariation.id } );

	const newProductVariation = { ...productVariation, productId };
	const newProductVariations = [ ...productVariations ];

	if ( -1 < index ) {
		newProductVariations[ index ] = newProductVariation;
	} else {
		newProductVariations.push( newProductVariation );
	}

	const promotions = calculatePromotions( state.coupons, state.products, newProductVariations );

	return { ...state, productVariations: newProductVariations, promotions };
}
function productVariationUpdated( state, action ) {
	const { data: productVariation, productId } = action;
	const productVariations = state.productVariations || [];
	const index = findIndex( productVariations, { id: productVariation.id } );

	const newProductVariation = { ...productVariation, productId };
	const newProductVariations = [ ...productVariations ];

	if ( -1 < index ) {
		newProductVariations[ index ] = newProductVariation;
	} else {
		newProductVariations.push( newProductVariation );
	}

	const promotions = calculatePromotions( state.coupons, state.products, newProductVariations );

	return { ...state, productVariations: newProductVariations, promotions };
}
function productVariationUpdated ( state , action ) { const { data : productVariation , productId } = action ; const productVariations = state . productVariations || [ ] ; const index = findIndex ( productVariations , { id : productVariation . id } ) ; const newProductVariation = { ... productVariation , productId } ; const newProductVariations = [ ... productVariations ] ; if ( - 1 < index ) { newProductVariations [ index ] = newProductVariation ; } else { newProductVariations . push ( newProductVariation ) ; } const promotions = calculatePromotions ( state . coupons , state . products , newProductVariations ) ; return { ... state , productVariations : newProductVariations , promotions } ; }
TODO: Update this for performance if needed. As-is, it will cause frequent recalculations.
TODO : Update this for performance if needed . As - is it will cause frequent recalculations .