-
Notifications
You must be signed in to change notification settings - Fork 15
Dwifft -> DifferenceKit #136
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
Preliminary tests using this with problem projects in PG look really good. Going to hold off putting in more effort here, until we can do more thorough testing internally. |
/// Creates a type-erased Differentiable for DiffableViewModel. | ||
/// These are only created internally from either `TableCellViewModel` or `CollectionCellViewModel`, | ||
/// so that we can safely force cast the models back to those types. | ||
public struct AnyDiffableViewModel { |
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 some of these helper types be made non-public?
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.
Nope. They're used in public methods/vars that are requirements of public protocols.
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.
If this struct is only used internally, can it be internal
instead of public
?
Maybe I'm misreading your 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.
AnyDiffableViewModel
is used in a decl that satisfies a protocol for a public type, so this has to be public.
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.
Ah, got it 👍
da98482
to
6d24e30
Compare
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.
Overall looks good! 💯
} | ||
self.refreshViews() |
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.
👌 Looks much cleaner
/// Creates a type-erased Differentiable for DiffableViewModel. | ||
/// These are only created internally from either `TableCellViewModel` or `CollectionCellViewModel`, | ||
/// so that we can safely force cast the models back to those types. | ||
public struct AnyDiffableViewModel { |
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.
If this struct is only used internally, can it be internal
instead of public
?
Maybe I'm misreading your comment?
Sources/Diffing.swift
Outdated
diffingKey: sectionModel.diffingKey | ||
) | ||
} | ||
} |
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.
🎉
|
||
/// MARK: - DifferenceKit Protocol Conformance | ||
|
||
extension TableSectionViewModel: DifferentiableSection { |
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.
@jessesquires AnyDiffableViewModel
is used to satisfy the DifferentiableSection
protocol. Because TableSectionViewModel
is public
, this protocol implementation must be made public (and cascades back to AnyDiffableViewModel
)
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.
Ah, got it 👍
I'm assuming this fixes #126 ? |
@jessesquires possibly? TBH, I can't tell what should be broken about UICollectionView diffing. AFAICT, the test issue I fixed in #131 was a test-only problem. |
e69beed
to
404dbc3
Compare
6d24e30
to
48423ca
Compare
48423ca
to
f155143
Compare
@jessesquires this is ready for final review! I think we're happy with internal testing cc @sasilukr |
@jessesquires oh wait no this still needs tests and changelog entry. will update again once that's done. |
@jessesquires
Thoughts? |
@benasher44 Either approach sounds reasonable. You can add the table/collection views to a UIWindow in the tests (I'm pretty sure). But, I'm leaning toward (1) — seems like we shouldn't be writing tests for the actual diffing lib. |
I think best way forward to fixing tests is leveraging protocol-based mocking. I've started with a PR for DifferenceKit: ra1028/DifferenceKit#27 |
@jessesquires adding the window, properly overriding performBatchUpdates, and remove some super calls gets tests to pass. This is ready for final approval! Also, confirmed #126 is fixed. |
Travis appears to be failing because their specs are out of date. |
897ba81
to
aed76d4
Compare
Generated by 🚫 Danger |
Added |
c9d02ae
to
c4cb560
Compare
self.model = model | ||
|
||
let differenceIdentifier = model.diffingKey | ||
/// Only compares diff identifiers. This means we'll never get "reload"-type `Changeset`s |
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.
hm... isn't this a problem? what if a cell updates it's content and needs to be refreshed? (but it's diff identifier wouldn't change...)
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 do it manually for the cells on screen in ReactiveLists, which is how it works today (Dwifft doesn't do reloads at all).
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 could revisit this in the future to see if this is something we want to support (using diffing to animate reloading of cells), but right now it would break forms (e.g. jumping fields because of keyboard dismissal)
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.
ah, right 👍 sounds good to me
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.
LGTM! 💯 🥇
Changes in this pull request
This swaps out Dwifft for DifferenceKit, which uses Paul Heckel's more efficient diffing algo (same one used by IGListKit). Most of the work here is adding layers to avoid
Self
/associatedtype
requirements issues with our protocols. These layers could be removed in the future though, pending changes that would allow this in Swift 5 or generics changes toTableViewModel
/CollectionViewModel
.This also fixes #126
Checklist
CHANGELOG.md
for any breaking changes, enhancements, or bug fixes.