Skip to content

Conversation

@evanpurkhiser
Copy link
Member

No description provided.

map[project.id] = project;
return map;
}, {});
const mapping = items.map(project => [project.id, project] as const);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't we call items projects?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll update 👍

Comment on lines +111 to +116
// Assign stats into projects
entries.forEach(([projectId, stats]) => {
this.itemsById[projectId].stats = stats;
});

const touchedIds = entries.map(([projectId]) => projectId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Assign stats into projects
entries.forEach(([projectId, stats]) => {
this.itemsById[projectId].stats = stats;
});
const touchedIds = entries.map(([projectId]) => projectId);
const touchedIds = entries.map(([projectId, stats]) => {
// Assign stats into projects
this.itemsById[projectId].stats = stats;
return projectId;
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol this is what it did before, but I hated that a map had side effects

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but this way, we don't need to do a 2x loop. Was the side effect negatively affecting anything?

Copy link
Member Author

@evanpurkhiser evanpurkhiser Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance difference is completely negligible. (O(2n) is the same as O(n))

The side effect was not affecting anything, but IMO it is harder to read.

From this article: https://glebbahmutov.com/blog/avoid-side-effects-with-immutable-data-structures/

When using immutable data structures instead of JavaScript native objects, our code and data flow becomes easier to understand and reason

Comment on lines +131 to +133
projects.forEach(project => this.removeTeamFromProject(teamSlug, project));

const affectedProjectIds = projects.map(project => project.id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
projects.forEach(project => this.removeTeamFromProject(teamSlug, project));
const affectedProjectIds = projects.map(project => project.id);
const affectedProjectIds = projects.map(project => {
this.removeTeamFromProject(teamSlug, project);
return project.id;
});

@evanpurkhiser evanpurkhiser merged commit e8c9a9f into master Nov 2, 2021
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-js-small-code-cleanup-to-projectsstore branch November 2, 2021 19:40
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants