Skip to content

Conversation

@stephencelis
Copy link
Member

Fixes #21 and a few other things, which I will review.

Copy link
Member Author

@stephencelis stephencelis left a 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!

Comment on lines +197 to +207
// 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.
"""
)
Copy link
Member Author

@stephencelis stephencelis May 6, 2020

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],
Copy link
Member Author

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.

Comment on lines 99 to 104
_modify {
yield &self.dictionary[id]
if self.dictionary[id] == nil {
self.ids.removeAll(where: { $0 == id })
}
}
Copy link
Member Author

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
Copy link
Member Author

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() {
Copy link
Member Author

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!

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.

Double Nested ForEachStore removal Bug

2 participants