UNPKG

reason-relay

Version:
78 lines (68 loc) 3.24 kB
// Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; var List = require("bs-platform/lib/js/list.js"); var Belt_List = require("bs-platform/lib/js/belt_List.js"); var Caml_option = require("bs-platform/lib/js/caml_option.js"); var RelayRuntime = require("relay-runtime"); function resolveNestedRecord(rootRecord, path) { var currentRecord = rootRecord; var pathLength = List.length(path); if (pathLength !== 0) { for(var i = 0; i < pathLength; ++i){ var currentPath = Belt_List.get(path, i); var match = currentRecord; currentRecord = match !== undefined && currentPath !== undefined ? Caml_option.nullable_to_opt(Caml_option.valFromOption(match).getLinkedRecord(currentPath, undefined)) : undefined; } } return currentRecord; } function resolveNestedRecordFromRoot(store, path) { if (!path) { return ; } var restPath = path.tl; var rootRecordPath = path.hd; if (restPath) { return resolveNestedRecord(Caml_option.nullable_to_opt(store.getRootField(rootRecordPath)), restPath); } var rootRecord = store.getRootField(rootRecordPath); if (!(rootRecord == null)) { return Caml_option.some(rootRecord); } } function removeNodeFromConnections(store, node, connections) { return Belt_List.forEach(connections, (function (connectionConfig) { var owner = store.get(connectionConfig.parentID); if (owner == null) { return ; } var connection = RelayRuntime.ConnectionHandler.getConnection(owner, connectionConfig.key, connectionConfig.filters !== undefined ? Caml_option.valFromOption(connectionConfig.filters) : undefined); if (!(connection == null)) { RelayRuntime.ConnectionHandler.deleteNode(connection, node.getDataID()); return ; } })); } function createAndAddEdgeToConnections(store, node, connections, edgeName, insertAt) { return Belt_List.forEach(connections, (function (connectionConfig) { var connectionOwner = store.get(connectionConfig.parentID); if (connectionOwner == null) { return ; } var connection = RelayRuntime.ConnectionHandler.getConnection(connectionOwner, connectionConfig.key, connectionConfig.filters !== undefined ? Caml_option.valFromOption(connectionConfig.filters) : undefined); if (connection == null) { return ; } var edge = RelayRuntime.ConnectionHandler.createEdge(store, connection, node, edgeName); if (insertAt) { RelayRuntime.ConnectionHandler.insertEdgeBefore(connection, edge, undefined); } else { RelayRuntime.ConnectionHandler.insertEdgeAfter(connection, edge, undefined); } })); } exports.resolveNestedRecord = resolveNestedRecord; exports.resolveNestedRecordFromRoot = resolveNestedRecordFromRoot; exports.removeNodeFromConnections = removeNodeFromConnections; exports.createAndAddEdgeToConnections = createAndAddEdgeToConnections; /* relay-runtime Not a pure module */