client/state/simple-payments/product-list/reducer.js
function addOrEditProduct( list = [], newProduct ) {
	let found = 0;
	const products = list.map( product => {
		if ( product.ID === newProduct.ID ) {
			found = 1;
			return newProduct;
		}
		return product;
	} );
	if ( ! found ) {
		return [ newProduct, ...products ];
	}
	return products;
}
function addOrEditProduct( list = [], newProduct ) {
	let found = 0;
	const products = list.map( product => {
		if ( product.ID === newProduct.ID ) {
			found = 1;
			return newProduct;
		}
		return product;
	} );
	if ( ! found ) {
		return [ newProduct, ...products ];
	}
	return products;
}
function addOrEditProduct ( list = [ ] , newProduct ) { let found = 0 ; const products = list . map ( product => { if ( product . ID === newProduct . ID ) { found = 1 ; return newProduct ; } return product ; } ) ; if ( ! found ) { return [ newProduct , ... products ] ; } return products ; }
Edits existing product if one with matching ID found.
Otherwise inserts the new one at the beginning of the list.
@param {Array} list of previous products
@param {Object} newProduct to update list with
@returns {Array} updated array of products
Edits existing product if one with matching ID found . Otherwise inserts the new one at the beginning of the list .