I am testing RxDataSources which requires the models to conform to the Equatable
and IdentifiableType
(similar to Identifiable
protocols.
I am using a unidirectional data flow to drive the UI and my model is the following enum:
enum ViewModelType: Equatable, IdentifiableType {
case loading
case post(Post)
var identity: String {
switch self {
case .loading: return "???" // <-- What to choose here?
case let .post(post): return String(post.id)
}
}
static func == (lhs: ViewModel.ViewModelType, rhs: ViewModel.ViewModelType) -> Bool {
switch (lhs, rhs) {
case (.loading, .loading): return true
case let (.post(l), .post(r)): return l == r
default: return false
}
}
}
}
Concerning the .loading
ViewModelType, I have to find a possible stable unique identifier if I want to use multiple ViewModelType of this type at once like [.loading, .loading, .loading]
or the diffing breaks from identical identifier
.
I prepared a sample project to reproduce the issue: https://github.com/florianldt/RxDataSourcesIdentifiableType
Any ideas of possible stable unique identifiers I can find for this use case.