relay-utils
Version:
Utilities for working with Relay (modern) in general, and the Relay store in particular.
26 lines (21 loc) • 480 B
Flow
// @flow
/**
* Collects all nodes from a connection and filters out nulls.
*/
export function collectConnectionNodes<T>(
connectionObj: ?{
+edges: ?$ReadOnlyArray<?{
+node: ?T
}>
}
): $ReadOnlyArray<T> {
if (connectionObj && connectionObj.edges && connectionObj.edges.length > 0) {
return connectionObj.edges.reduce((acc, curr) => {
if (curr && curr.node) {
acc.push(curr.node);
}
return acc;
}, []);
}
return [];
}