This file contains hidden or 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
export default initialState => { | |
const stateEntriesNames = Object.keys(initialState) | |
const reducer = (state, action) => stateEntriesNames.includes(action.type) ? ({ ...new Map(state).set(action.type, action.payload) }) : initialState | |
const setters = stateEntriesNames.reduce((acc, next) => ({ ...acc, [next]: payload => ({ type: next, payload }) }), {}) | |
return { reducer, setters } | |
} |
This file contains hidden or 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
var graph1 = { | |
vertex: ["1","2","3"], | |
edge: [, | |
/* vertex1, vertex2, weight */ | |
["1", "2", 4], | |
["1", "3", 7], | |
["2", "3", 1] | |
] | |
}, | |
graph2 = { |