-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Assorted fixes for collections of state #25
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
Conversation
stephencelis
left a comment
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.
Here's a quick overview of the changes!
| // NB: This does not need to be a fatal error because of the index subscript that follows it. | ||
| assert( | ||
| index < globalState[keyPath: toLocalState].endIndex, | ||
| """ | ||
| Index out of range. This can happen when a reducer that can remove the last element from \ | ||
| an array is then combined with a "forEach" from that array. To avoid this and other \ | ||
| index-related gotchas, consider using an "IdentifiedArray" of state instead. Or, combine \ | ||
| your reducers so that the "forEach" comes before any reducer that can remove elements from \ | ||
| its array. | ||
| """ | ||
| ) |
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.
This error message should help fix #21. We can finesse the wording if any of it could be improved.
| return self.optional | ||
| .reducer( | ||
| &globalState[keyPath: toLocalState][id], | ||
| &globalState[keyPath: toLocalState][id: id], |
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.
I've updated the interface to take an explicit id parameter to avoid any ambiguity for Int-based ids.
| _modify { | ||
| yield &self.dictionary[id] | ||
| if self.dictionary[id] == nil { | ||
| self.ids.removeAll(where: { $0 == id }) | ||
| } | ||
| } |
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.
We weren't properly cleaning up the ids array when nil-ing out elements.
| } | ||
| } | ||
|
|
||
| @discardableResult |
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.
Stumbled upon this warning when writing tests.
|
|
||
| public mutating func remove(atOffsets offsets: IndexSet) { | ||
| for offset in offsets { | ||
| for offset in offsets.reversed() { |
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.
Tests caught a bug here, as well!
Fixes #21 and a few other things, which I will review.