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

Possible issue with NSTableView binding #653

Open
killev opened this issue Aug 4, 2019 · 3 comments
Open

Possible issue with NSTableView binding #653

killev opened this issue Aug 4, 2019 · 3 comments
Labels

Comments

@killev
Copy link
Contributor

killev commented Aug 4, 2019

Working on collections/changesets I found a possible issue:

               case .next(let element):
                   let newCollection = element
                   if let collection = collection {
                       let diff = generateDiff(collection, newCollection)
                       observer.receive(OrderedCollectionChangeset(collection: newCollection, patch: [], diff: diff))
                   } else {
                       observer.receive(OrderedCollectionChangeset(collection: newCollection, patch: []))
                   }
                   collection = newCollection

Line:

observer.receive(OrderedCollectionChangeset(collection: newCollection, patch: [], diff: diff))

I think this is a mistake. You shouldn't pass patch option there.
Then this patch will be used here:

 open func apply(changeset: Changeset) {
        guard let tableView = tableView else { return }
        let patch = changeset.patch
        if patch.isEmpty {
            collection = clone(changeset.collection)
            tableView.reloadData()
        } else {
            tableView.beginUpdates()
            patch.forEach(apply)
            tableView.endUpdates()
        }
    }

And as far as it's empty it always reloadData.

@srdanrasic
Copy link
Contributor

Good catch 👍

@srdanrasic srdanrasic added the Bug label Aug 5, 2019
@killev
Copy link
Contributor Author

killev commented Aug 5, 2019

Fixed in #654

@killev
Copy link
Contributor Author

killev commented Aug 5, 2019

How about removing the constructor which accepts both arguments:

    public init(collection: Collection, patch: [Operation], diff: Diff) {
        self.collection = collection
        self.precalculatedPatch = patch
        self.precalculatedDiff = diff
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants