Using DataCore - dsriseah/ursys GitHub Wiki

Pseudocode for DataCore Structure

uses URNET calls; see Using URSYS Messages

/** import external libs **/

import * as UR from '@ursys/core'
import { graph } from 'graphlib';

/** declare data structures **/

graph.setNodes.new Map();
graph.setEdges.new Map();

/** initialize data structures during LOAD_ASSETS phase **/

UR.Hook('LOAD_ASSETS', ()=>{
  return UR.Call('NET:SRV_GET_GRAPH', data => {
    const { nodes, edges } = data;
    graph.setNodes(nodes);
    graph.setEdges(edges);
  }); // Promise
});

/** API Methods **/

function GetGraph() {
  return { 
    nodes: graph.getNodes().values(),
    edges: graph.getEdges().values()
  }
}

function UpdateGraph(graphData) {
  const { nodes, edges } = graphData;
  const g = { nodes, edges };
  graph.update(g);
  m_UpdateGraphDB(g);
}

/** non-exported helper function **/

function m_UpdateGraphDB(graphData) {
  UR.Call('NET:SRV_UPDATE_GRAPH',nodeData)
  .then(data=>{
    const { err, changed, new, modified } = data;
    if (err) throw Error(`error on db update ${err}`);
    else UR.Signal('GRAPH_UPDATE, {changed, new, modified});
  });
}

/** register network graph update event **/

UR.Subscribe('NET:SRV_GRAPH_UPDATED', data => {
  const { changed, new, modified } = data;
  graph.updateAllTheThings(changed, new, modified);
  UR.Signal('GRAPH_UPDATE, {changed, new, modified});
});

/** module exports **/

export {
  GetNodesAsArray, 
  UpdateNode
}
 
⚠️ **GitHub.com Fallback** ⚠️