Skip to content

Conversation

@OleksandrMizov
Copy link

Implementation of the delta OR set

}

remove(item) {
const result = init();
Copy link
Member

Choose a reason for hiding this comment

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

Could be better to return the new instance of this class (or another one) instead of a plain object

add(item, tag = crypto.randomUUID()) {
const result = init();
const added = this.#added[item];
result.added[item] = added ? new Set([...added, tag]) : new Set([tag]);
Copy link
Member

Choose a reason for hiding this comment

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

For brevity:

Suggested change
result.added[item] = added ? new Set([...added, tag]) : new Set([tag]);
result.added[item] = new Set([...(added || []), tag]);

Comment on lines 39 to 40
for (const [item, tags] of added) {
const deltaTags = tags || new Set();
Copy link
Member

Choose a reason for hiding this comment

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

Can be simplified, since we always have a set there

Suggested change
for (const [item, tags] of added) {
const deltaTags = tags || new Set();
for (const [item, deltaTags] of added) {

Comment on lines 47 to 48
const removed = Object.entries(delta.removed);
for (const [item, tags] of removed) {
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
const removed = Object.entries(delta.removed);
for (const [item, tags] of removed) {
for (const [item, tags] of Object.entries(delta.removed)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants