Skip to content
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

Buggy default reload method #134

Open
3 tasks done
gerchicov-bp opened this issue Aug 26, 2021 · 1 comment
Open
3 tasks done

Buggy default reload method #134

gerchicov-bp opened this issue Aug 26, 2021 · 1 comment

Comments

@gerchicov-bp
Copy link

Checklist

Expected Behavior

Table reloads

Current Behavior

Table reloading failed with exception:
Thread 1: "attempt to insert row 0 into section 1, but there are only 0 rows in section 1 after the update"

Steps to Reproduce

Code example:

class Item { ... }
class Group {
var isExpanded = true
var items: [Item] = ...
func visibleItems() -> [Item] { isExpanded ? self.items : [] }
...
}
var groups: [Group] = {
  let group = Group()
  group.items = Item()
  return [group]
}()

Where groups represent sections and items represent rows. Just expand-collapse a section (isExpanded changed), calc the diff and try to reload the table with these data using any method in this library.

Detailed Description (Include Screenshots)

The problem is in your reload method which attempts to reload data step-by-step. In my case it means on expand it attempts to add one Item and insert it into the table immediately ignoring isExpanded value which should be updated in the next run loop.

Reproducible Demo Project

I don't have but it seems the task is trivial to reproduce.

Environments

Doesn't matter because there is an error inside this library algo.

@gerchicov-bp
Copy link
Author

It seems the problem is with this code:

// The 4th stage changeset.
        // - Includes:
        //   - element inserts
        //   - element moves
        if !elementInserted.isEmpty || !elementMoved.isEmpty {
            changesets.append(
                Changeset(
                    data: Collection(fourthStageSections),
                    elementInserted: elementInserted,
                    elementMoved: elementMoved
                )
            )
        }

        // The 5th stage changeset.
        // - Includes:
        //   - section updates
        if !sectionResult.updated.isEmpty {
            changesets.append(
                Changeset(
                    data: target,
                    sectionUpdated: sectionResult.updated
                )
            )
        }

In my case element inserts and section updates should be inside the same changeset, not separate changesets. So it seems it is a problem of your algo.

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

No branches or pull requests

1 participant