UNPKG

cywidget-network

Version:

Simple network viewer widget based on Cytoscape.js and React.js.

53 lines (42 loc) 978 B
import { NODE_SELECTED, EDGE_SELECTED, RECEIVE_NETWORK, REQUEST_NETWORK } from "../actions/Actions.jsx" let EMPTY_GRAPH = { elements: [] }; let INITIAL_STATE = { graph: EMPTY_GRAPH, selected: null, graphUrl: '', isFetching: false }; export default function graphReducer(state = INITIAL_STATE, action) { // console.log("====== ACT"); // console.log(action) // console.log("====== state"); // console.log(state); switch (action.type) { case REQUEST_NETWORK: return Object.assign({}, state, { graphUrl: action.graphUrl, isFetching: true }); case RECEIVE_NETWORK: return Object.assign({}, state, { graph: action.graph, graphUrl: action.graphUrl, isFetching: false }) case NODE_SELECTED: case EDGE_SELECTED: return Object.assign({}, state, { graphUrl: action.graphUrl, selected: action.selected }) default: return state; } }