1- import forEach from 'lodash.foreach'
21import * as diffpatcher from './utils/diffpatcher'
32import { buildBaseAttributesActions } from './utils/common-actions'
43import createBuildArrayActions , {
@@ -71,30 +70,31 @@ function _buildDeliveryParcelsAction(
7170 oldDelivery . parcels ,
7271 newDelivery . parcels
7372 )
74- forEach ( diffedParcels , ( parcel , key ) => {
75- const { oldObj } = extractMatchingPairs (
76- matchingParcelPairs ,
77- key ,
78- oldDelivery . parcels ,
79- newDelivery . parcels
80- )
73+ diffedParcels &&
74+ Object . entries ( diffedParcels ) . forEach ( ( [ key , parcel ] ) => {
75+ const { oldObj } = extractMatchingPairs (
76+ matchingParcelPairs ,
77+ key ,
78+ oldDelivery . parcels ,
79+ newDelivery . parcels
80+ )
8181
82- if ( isAddAction ( key , parcel ) ) {
83- addParcelActions . push ( {
84- action : 'addParcelToDelivery' ,
85- deliveryId : oldDelivery . id ,
86- ...diffpatcher . getDeltaValue ( parcel ) ,
87- } )
88- return
89- }
82+ if ( isAddAction ( key , parcel ) ) {
83+ addParcelActions . push ( {
84+ action : 'addParcelToDelivery' ,
85+ deliveryId : oldDelivery . id ,
86+ ...diffpatcher . getDeltaValue ( parcel ) ,
87+ } )
88+ return
89+ }
9090
91- if ( isRemoveAction ( key , parcel ) ) {
92- removeParcelActions . push ( {
93- action : 'removeParcelFromDelivery' ,
94- parcelId : oldObj . id ,
95- } )
96- }
97- } )
91+ if ( isRemoveAction ( key , parcel ) ) {
92+ removeParcelActions . push ( {
93+ action : 'removeParcelFromDelivery' ,
94+ parcelId : oldObj . id ,
95+ } )
96+ }
97+ } )
9898
9999 return [ addParcelActions , removeParcelActions ]
100100}
@@ -116,7 +116,12 @@ function _buildDeliveryItemsAction(diffedItems, newDelivery: any = {}) {
116116 return [ setDeliveryItemsAction ]
117117}
118118
119- export function actionsMapParcels ( diff , oldObj , newObj , deliveryHashMap ) {
119+ export function actionsMapParcels (
120+ diff : { shippingInfo : { deliveries : { any } } } ,
121+ oldObj ,
122+ newObj ,
123+ deliveryHashMap
124+ ) {
120125 const shippingInfo = diff . shippingInfo
121126 if ( ! shippingInfo ) return [ ]
122127
@@ -127,7 +132,7 @@ export function actionsMapParcels(diff, oldObj, newObj, deliveryHashMap) {
127132 let removeParcelActions = [ ]
128133
129134 if ( deliveries )
130- forEach ( deliveries , ( delivery , key ) => {
135+ Object . entries ( deliveries ) . forEach ( ( [ key , delivery ] ) => {
131136 const { oldObj : oldDelivery , newObj : newDelivery } = extractMatchingPairs (
132137 deliveryHashMap ,
133138 key ,
@@ -150,7 +155,12 @@ export function actionsMapParcels(diff, oldObj, newObj, deliveryHashMap) {
150155 return removeParcelActions . concat ( addParcelActions )
151156}
152157
153- export function actionsMapDeliveryItems ( diff , oldObj , newObj , deliveryHashMap ) {
158+ export function actionsMapDeliveryItems (
159+ diff : { shippingInfo : { deliveries : { any } } } ,
160+ oldObj ,
161+ newObj ,
162+ deliveryHashMap
163+ ) {
154164 const shippingInfo = diff . shippingInfo
155165 if ( ! shippingInfo ) return [ ]
156166
@@ -159,7 +169,7 @@ export function actionsMapDeliveryItems(diff, oldObj, newObj, deliveryHashMap) {
159169
160170 let setDeliveryItemsActions = [ ]
161171
162- forEach ( deliveries , ( delivery , key ) => {
172+ Object . entries ( deliveries ) . forEach ( ( [ key , delivery ] ) => {
163173 const { newObj : newDelivery } = extractMatchingPairs (
164174 deliveryHashMap ,
165175 key ,
0 commit comments