-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #301 - Register inputEntities & inputRelationships in mockJobState #313
Conversation
inputEntities.forEach((e) => { | ||
duplicateKeyTracker.registerKey(e._key, { | ||
_type: e._type, | ||
}); | ||
typeTracker.registerType(e._type); | ||
}); | ||
inputRelationships.forEach((r) => { | ||
duplicateKeyTracker.registerKey(r._key as string, { | ||
_type: r._type, | ||
}); | ||
typeTracker.registerType(r._type as string); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about moving this logic below the const ...
function declarations, just before the return ...
:
addEntities(inputEntities);
addRelationships(inputRelationships);
I might be missing a finer detail 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aiwilliams the addEntities
and addRelationships
functions also push graph objects onto the collected<GraphObjects>
list. That breaks tests since collected<GraphObjects>
should only contain graph objects that were added during the step.
I could alternatively refactor a bit to something like this:
const addEntitiesToDuplicateKeyTracker = (newEntities: Entity[]) => {
newEntities.forEach((e) => {
duplicateKeyTracker.registerKey(e._key, {
_type: e._type,
});
typeTracker.registerType(e._type);
});
};
addEntitiesToDuplicateKeyTracker(inputEntities);
const addEntities = async (newEntities: Entity[]): Promise<Entity[]> => {
addEntitiesToDuplicateKeyTracker(newEntities);
collectedEntities = collectedEntities.concat(newEntities);
return Promise.resolve(newEntities);
}
const addRelationshipsToDuplicateKeyTracker = (newRelationships: Relationship[]) => {
newRelationships.forEach((r) => {
duplicateKeyTracker.registerKey(r._key as string, {
_type: r._type,
});
typeTracker.registerType(r._type as string);
});
};
addRelationshipsToDuplicateKeyTracker(inputRelationships);
const addRelationships = async (newRelationships: Relationship[]) => {
addRelationshipsToDuplicateKeyTracker(newRelationships);
collectedRelationships = collectedRelationships.concat(newRelationships);
return Promise.resolve();
};
const iterateEntities = async <T extends Entity = Entity>(
filter,
iteratee,
) => {
const filteredEntities = [...inputEntities, ...collectedEntities].filter(
(e) => e._type === filter._type,
);
for (const entity of filteredEntities as T[]) {
await iteratee(entity);
}
};
It removes duplicate code which may be worth the change, but it's still not particularly attractive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying for me!
No description provided.