Skip to content

Commit c75cb24

Browse files
committed
feat(migrate): remove lodash.forEach
1 parent 9b976f2 commit c75cb24

File tree

6 files changed

+412
-394
lines changed

6 files changed

+412
-394
lines changed

packages/sync-actions/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"dependencies": {
2626
"fast-equals": "^2.0.0",
2727
"jsondiffpatch": "^0.4.0",
28-
"lodash.foreach": "^4.5.0",
2928
"lodash.intersection": "^4.4.0",
3029
"lodash.isequal": "^4.5.0",
3130
"lodash.isnil": "^4.0.0",

packages/sync-actions/src/order-actions.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import forEach from 'lodash.foreach'
21
import * as diffpatcher from './utils/diffpatcher'
32
import { buildBaseAttributesActions } from './utils/common-actions'
43
import 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

Comments
 (0)