github.com/replicatedhq/ship@v0.55.0/web/init/src/redux/data/kustomizeOverlay/reducer.js (about) 1 import { constants } from "./actions"; 2 import uniqBy from "lodash/uniqBy"; 3 4 const kustomizeState = { 5 fileContents: [], 6 patch: "", 7 modified: "", 8 }; 9 10 function updateFileContents(currState, data) { 11 const nextFiles = currState.fileContents; 12 const transformed = { 13 baseContent: data.content.base, 14 overlayContent: data.content.overlay, 15 key: data.path, 16 isSupported: data.content.isSupported, 17 isResource: data.content.isResource 18 } 19 nextFiles.unshift(transformed); // add to front of array so uniqBy will keep newest version 20 return uniqBy(nextFiles, "key"); 21 } 22 23 export function kustomizeData(state = kustomizeState, action) { 24 switch (action.type) { 25 case constants.RECEIVE_FILE_CONTENT: 26 const updatedContents = updateFileContents(state, action.payload); 27 return Object.assign({}, state, { 28 fileContents: updatedContents 29 }); 30 case constants.RECEIVE_PATCH: { 31 const { patch } = action.payload; 32 return Object.assign({}, state, { 33 patch, 34 }); 35 } 36 case constants.RECEIVE_MODIFIED: 37 const { modified, patch } = action.payload; 38 return Object.assign({}, state, { 39 modified, 40 patch, 41 }); 42 default: 43 return state; 44 } 45 }