rescript-relay
Version:
Use Relay with ReScript.
74 lines (67 loc) • 2.87 kB
JavaScript
// Generated by ReScript, PLEASE EDIT WITH CARE
;
let Stdlib_List = require("@rescript/runtime/lib/js/Stdlib_List.js");
let RelayRuntime = require("relay-runtime");
let Primitive_option = require("@rescript/runtime/lib/js/Primitive_option.js");
function resolveNestedRecord(rootRecord, path) {
let currentRecord = rootRecord;
let pathLength = Stdlib_List.length(path);
if (pathLength !== 0) {
for (let i = 0; i < pathLength; ++i) {
let currentPath = Stdlib_List.get(path, i);
let match = currentRecord;
currentRecord = match !== undefined && currentPath !== undefined ? Primitive_option.fromNullable(Primitive_option.valFromOption(match).getLinkedRecord(currentPath)) : undefined;
}
}
return currentRecord;
}
function resolveNestedRecordFromRoot(store, path) {
if (path === 0) {
return;
}
let restPath = path.tl;
let rootRecordPath = path.hd;
if (restPath !== 0) {
return resolveNestedRecord(Primitive_option.fromNullable(store.getRootField(rootRecordPath)), restPath);
}
let rootRecord = store.getRootField(rootRecordPath);
if (!(rootRecord == null)) {
return Primitive_option.some(rootRecord);
}
}
function removeNodeFromConnections(store, node, connections) {
Stdlib_List.forEach(connections, connectionConfig => {
let owner = store.get(connectionConfig.parentID);
if (owner == null) {
return;
}
let connection = RelayRuntime.ConnectionHandler.getConnection(owner, connectionConfig.key, connectionConfig.filters !== undefined ? Primitive_option.valFromOption(connectionConfig.filters) : undefined);
if (!(connection == null)) {
RelayRuntime.ConnectionHandler.deleteNode(connection, node.getDataID());
return;
}
});
}
function createAndAddEdgeToConnections(store, node, connections, edgeName, insertAt) {
Stdlib_List.forEach(connections, connectionConfig => {
let connectionOwner = store.get(connectionConfig.parentID);
if (connectionOwner == null) {
return;
}
let connection = RelayRuntime.ConnectionHandler.getConnection(connectionOwner, connectionConfig.key, connectionConfig.filters !== undefined ? Primitive_option.valFromOption(connectionConfig.filters) : undefined);
if (connection == null) {
return;
}
let edge = RelayRuntime.ConnectionHandler.createEdge(store, connection, node, edgeName);
if (insertAt === "Start") {
RelayRuntime.ConnectionHandler.insertEdgeAfter(connection, edge);
return;
}
RelayRuntime.ConnectionHandler.insertEdgeBefore(connection, edge);
});
}
exports.resolveNestedRecord = resolveNestedRecord;
exports.resolveNestedRecordFromRoot = resolveNestedRecordFromRoot;
exports.removeNodeFromConnections = removeNodeFromConnections;
exports.createAndAddEdgeToConnections = createAndAddEdgeToConnections;
/* relay-runtime Not a pure module */