@@ -104,13 +104,17 @@ function _buildNewSetProductAttributeAction(attr) {
104104 return action
105105}
106106
107- function _buildNewSetAttributeAction ( variantId , attr , sameForAllAttributeNames ) {
107+ function _buildNewSetAttributeAction (
108+ variantId ,
109+ attr ,
110+ sameForAllAttributeNames
111+ ) {
108112 const attributeName = attr && attr . name
109113 if ( ! attributeName ) return undefined
110114
111115 let action = {
112116 action : 'setAttribute' ,
113- variantId : variantId ,
117+ variantId,
114118 name : attributeName ,
115119 value : attr . value ,
116120 }
@@ -123,7 +127,11 @@ function _buildNewSetAttributeAction(variantId, attr, sameForAllAttributeNames)
123127 return action
124128}
125129
126- function _buildAttributeValue ( diffedValue , oldAttributeValue , newAttributeValue ) {
130+ function _buildAttributeValue (
131+ diffedValue ,
132+ oldAttributeValue ,
133+ newAttributeValue
134+ ) {
127135 let value
128136
129137 if ( Array . isArray ( diffedValue ) )
@@ -174,7 +182,11 @@ function _buildAttributeValue(diffedValue, oldAttributeValue, newAttributeValue)
174182 return value
175183}
176184
177- function _buildSetProductAttributeAction ( diffedValue , oldProductData , newAttribute ) {
185+ function _buildSetProductAttributeAction (
186+ diffedValue ,
187+ oldProductData ,
188+ newAttribute
189+ ) {
178190 if ( ! newAttribute ) return undefined
179191
180192 const action = {
@@ -186,7 +198,11 @@ function _buildSetProductAttributeAction(diffedValue, oldProductData, newAttribu
186198 const oldAttribute =
187199 oldProductData . attributes . find ( ( a ) => a . name === newAttribute . name ) || { }
188200
189- action . value = _buildAttributeValue ( diffedValue , oldAttribute . value , newAttribute . value )
201+ action . value = _buildAttributeValue (
202+ diffedValue ,
203+ oldAttribute . value ,
204+ newAttribute . value
205+ )
190206
191207 return action
192208}
@@ -214,7 +230,11 @@ function _buildSetAttributeAction(
214230 delete action . variantId
215231 }
216232
217- action . value = _buildAttributeValue ( diffedValue , oldAttribute . value , attribute . value )
233+ action . value = _buildAttributeValue (
234+ diffedValue ,
235+ oldAttribute . value ,
236+ attribute . value
237+ )
218238
219239 return action
220240}
@@ -373,16 +393,12 @@ function _buildProductAttributesActions(
373393 if ( ! diffedAttributes ) return actions
374394
375395 forEach ( diffedAttributes , ( value , key ) => {
376- // What does this test tell us?
377396 if ( REGEX_NUMBER . test ( key ) ) {
378- // What does this test tell us?
379397 if ( Array . isArray ( value ) ) {
380- // Whats the difference between _buildNew... and _build... ?
381398 const setAction = _buildNewSetProductAttributeAction (
382399 diffpatcher . getDeltaValue ( value )
383400 )
384401 if ( setAction ) actions . push ( setAction )
385- // What does this test tell us?
386402 } else if ( newProductData . attributes ) {
387403 const setAction = _buildSetProductAttributeAction (
388404 value . value ,
@@ -391,29 +407,24 @@ function _buildProductAttributesActions(
391407 )
392408 if ( setAction ) actions . push ( setAction )
393409 }
394- // What does this test tell us?
395410 } else if ( REGEX_UNDERSCORE_NUMBER . test ( key ) ) {
396411 if ( Array . isArray ( value ) ) {
397- // What does this test tell us?
398412 // Ignore pure array moves!
399413 if ( value . length === 3 && value [ 2 ] === 3 ) return
400414
401415 let deltaValue = diffpatcher . getDeltaValue ( value )
402416
403- // What happens here?
404417 if ( ! deltaValue )
405418 if ( value [ 0 ] && value [ 0 ] . name )
406419 // unset attribute if
407420 deltaValue = { name : value [ 0 ] . name }
408421 else deltaValue = undefined
409422
410- const setAction = _buildNewSetProductAttributeAction (
411- deltaValue
412- )
423+ const setAction = _buildNewSetProductAttributeAction ( deltaValue )
413424
414425 if ( setAction ) actions . push ( setAction )
415426 } else {
416- const index = key . substring ( 1 ) // what happens here? Shouldn't this always be underscore?
427+ const index = key . substring ( 1 )
417428 if ( newProductData . attributes ) {
418429 const setAction = _buildSetProductAttributeAction (
419430 value . value ,
@@ -761,7 +772,7 @@ export function actionsMapAssets(diff, oldObj, newObj, variantHashMap) {
761772export function actionsMapProductAttributes (
762773 diffedProductData ,
763774 oldProductData ,
764- newProductData ,
775+ newProductData
765776) {
766777 return _buildProductAttributesActions (
767778 diffedProductData . attributes ,
@@ -770,7 +781,7 @@ export function actionsMapProductAttributes(
770781 )
771782}
772783
773- export function actionsMapVariantAttributes (
784+ export function actionsMapAttributes (
774785 diff ,
775786 oldObj ,
776787 newObj ,
0 commit comments