-
Notifications
You must be signed in to change notification settings - Fork 1
Add delta OR set implementation #2
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
base: master
Are you sure you want to change the base?
Add delta OR set implementation #2
Conversation
DeltaBased/2-or-set.js
Outdated
| } | ||
|
|
||
| remove(item) { | ||
| const result = init(); |
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.
Could be better to return the new instance of this class (or another one) instead of a plain object
DeltaBased/2-or-set.js
Outdated
| add(item, tag = crypto.randomUUID()) { | ||
| const result = init(); | ||
| const added = this.#added[item]; | ||
| result.added[item] = added ? new Set([...added, tag]) : new Set([tag]); |
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.
For brevity:
| result.added[item] = added ? new Set([...added, tag]) : new Set([tag]); | |
| result.added[item] = new Set([...(added || []), tag]); |
DeltaBased/2-or-set.js
Outdated
| for (const [item, tags] of added) { | ||
| const deltaTags = tags || new Set(); |
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.
Can be simplified, since we always have a set there
| for (const [item, tags] of added) { | |
| const deltaTags = tags || new Set(); | |
| for (const [item, deltaTags] of added) { |
DeltaBased/2-or-set.js
Outdated
| const removed = Object.entries(delta.removed); | ||
| for (const [item, tags] of removed) { |
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.
| const removed = Object.entries(delta.removed); | |
| for (const [item, tags] of removed) { | |
| for (const [item, tags] of Object.entries(delta.removed)) { |
Implementation of the delta OR set