Merge branch 'master' into minIOS11

# Conflicts:
#	Sources/ListSnapshot.swift
This commit is contained in:
John Estropia
2020-11-11 13:44:58 +09:00
8 changed files with 190 additions and 23 deletions

View File

@@ -71,7 +71,7 @@ public struct ListSnapshot<O: DynamicObject>: RandomAccessCollection, Hashable {
public subscript(index: Index) -> ObjectPublisher<O> {
let context = self.context!
let itemID = self.diffableSnapshot.itemIdentifiers[index]
let itemID = self.diffableSnapshot.itemIdentifier(atAllItemsIndex: index)!
return context.objectPublisher(objectID: itemID)
}
@@ -83,16 +83,13 @@ public struct ListSnapshot<O: DynamicObject>: RandomAccessCollection, Hashable {
*/
public subscript(safeIndex index: Index) -> ObjectPublisher<O>? {
guard let context = self.context else {
guard
let context = self.context,
let itemID = self.diffableSnapshot.itemIdentifier(atAllItemsIndex: index)
else {
return nil
}
let itemIDs = self.diffableSnapshot.itemIdentifiers
guard itemIDs.indices.contains(index) else {
return nil
}
let itemID = itemIDs[index]
return context.objectPublisher(objectID: itemID)
}
@@ -610,19 +607,61 @@ public struct ListSnapshot<O: DynamicObject>: RandomAccessCollection, Hashable {
return self.diffableSnapshot.numberOfItems
}
public func index(after i: Index) -> Index {
return i + 1
}
public func formIndex(after i: inout Index) {
return i += 1
}
public func index(before i: Index) -> Index {
return i - 1
}
public func formIndex(before i: inout Index) {
return i -= 1
}
// MARK: BidirectionalCollection
public func index(_ i: Int, offsetBy distance: Int) -> Int {
public func index(_ i: Index, offsetBy distance: Int) -> Index {
return i + distance
}
public func distance(from start: Int, to end: Int) -> Int {
public func index(_ i: Index, offsetBy distance: Int, limitedBy limit: Int) -> Index? {
let length = limit - i
if distance > 0
? length >= 0 && length < distance
: length <= 0 && length > distance {
return nil
}
return i + distance
}
public func distance(from start: Index, to end: Index) -> Int {
return end - start
}
public subscript(bounds: Range<Index>) -> ArraySlice<Element> {
guard let context = self.context else {
return .init()
}
let itemIDs = self.diffableSnapshot.itemIdentifiers(atAllItemsBounds: bounds)
return ArraySlice(itemIDs.map(context.objectPublisher(objectID:)))
}
// MARK: Sequence