| 2164 | |
| 2165 | // refs are equal only at the same path |
| 2166 | export const uniqueFlatRefs = (refs: FlatRef[]): FlatRef[] => { |
| 2167 | const refsByPath = new Map<string, FlatRef[]>() |
| 2168 | return refs.filter(ref => { |
| 2169 | const atPath = refsByPath.get(ref.propString) |
| 2170 | if (!atPath) refsByPath.set(ref.propString, [ref]) |
| 2171 | else if (atPath.some(existing => existing.node.equals(ref.node))) |
| 2172 | return false |
| 2173 | else atPath.push(ref) |
| 2174 | return true |
| 2175 | }) |
| 2176 | } |
| 2177 | |
| 2178 | export const appendUniqueNodes = <node extends BaseNode>( |
| 2179 | existing: node[] | undefined, |