relay-utils
Version:
Utilities for working with Relay (modern) in general, and the Relay store in particular.
66 lines (54 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.removeNodeFromStore = removeNodeFromStore;
var _relayRuntime = require("relay-runtime");
function removeNodeFromStore(store, config) {
var node = config.node;
if (!node) {
if (__DEV__) {
console.warn('Could not find source node');
}
return;
}
if (config.connections) {
config.connections.forEach(function (connectionConfig) {
var owner = store.get(connectionConfig.parentID);
if (owner) {
var connection = _relayRuntime.ConnectionHandler.getConnection(owner, connectionConfig.key, connectionConfig.filters);
if (connection) {
_relayRuntime.ConnectionHandler.deleteNode(connection, node.getDataID());
} else {
if (__DEV__) {
console.warn('Could not find connection.');
}
}
} else {
if (__DEV__) {
console.warn('Could not find owner');
}
}
});
}
if (config.linkedRecords) {
config.linkedRecords.forEach(function (linkedRecordConfig) {
var owner = store.get(linkedRecordConfig.parentID);
if (owner) {
var linkedRecord = owner.getLinkedRecord(linkedRecordConfig.key, linkedRecordConfig.filters);
if (linkedRecord) {
_relayRuntime.ConnectionHandler.deleteNode(linkedRecord, node.getDataID());
} else {
if (__DEV__) {
console.warn('Could not find linked record');
}
}
} else {
if (__DEV__) {
console.warn('Could not find owner');
}
}
});
}
store["delete"](node.getDataID());
}