-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
851 additions
and
840 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import createBuildArrayActions, { | ||
ADD_ACTIONS, | ||
CHANGE_ACTIONS, | ||
REMOVE_ACTIONS, | ||
} from './utils/create-build-array-actions' | ||
import { | ||
CategoryAddAssetAction, | ||
CategoryRemoveAssetAction, | ||
} from '@commercetools/platform-sdk' | ||
import { UpdateAction } from '@commercetools/sdk-client-v2' | ||
|
||
function toAssetIdentifier(asset: { id?: string; key?: string }) { | ||
return asset.id ? { assetId: asset.id } : { assetKey: asset.key } | ||
} | ||
|
||
export default function actionsMapAssets(diff: any, oldObj: any, newObj: any) { | ||
const handler = createBuildArrayActions('assets', { | ||
[ADD_ACTIONS]: (newAsset): CategoryAddAssetAction => ({ | ||
action: 'addAsset', | ||
asset: newAsset, | ||
}), | ||
[REMOVE_ACTIONS]: (oldAsset): CategoryRemoveAssetAction => ({ | ||
action: 'removeAsset', | ||
...toAssetIdentifier(oldAsset), | ||
}), | ||
[CHANGE_ACTIONS]: (oldAsset, newAsset): Array<UpdateAction> => | ||
// here we could use more atomic update actions (e.g. changeAssetName) | ||
// but for now we use the simpler approach to first remove and then | ||
// re-add the asset - which reduces the code complexity | ||
{ | ||
return [ | ||
{ | ||
action: 'removeAsset', | ||
...toAssetIdentifier(oldAsset), | ||
}, | ||
{ | ||
action: 'addAsset', | ||
asset: newAsset, | ||
}, | ||
] | ||
}, | ||
}) | ||
|
||
return handler(diff, oldObj, newObj) | ||
} |
Oops, something went wrong.