Structures
The following structures are available globally.
-
An ordered collection of
Changeset
as staged set of changes in the sectioned collection.The order is representing the stages of changesets.
We know that there are combination of changes that crash when applied simultaneously in batch-updates of UI such as UITableView or UICollectionView. The
StagedChangeset
created from the two collection is split at the minimal stages that can be perform batch-updates with no crashes.Example for calculating differences between the two linear collections.
extension String: Differentiable {} let source = ["A", "B", "C"] let target = ["B", "C", "D"] let changeset1 = StagedChangeset(source: source, target: target) print(changeset1.isEmpty) // prints "false"
Example for calculating differences between the two sectioned collections.
See morelet source = [ Section(model: "A", elements: ["😉"]), ] let target = [ Section(model: "A", elements: ["😉, 😺"]), Section(model: "B", elements: ["😪"]) ] let changeset2 = StagedChangeset(source: sectionedSource, target: sectionedTarget) print(changeset2.isEmpty) // prints "false"
Declaration
Swift
public struct StagedChangeset<Collection> where Collection : Collection
-
A type-erased differentiable value.
The
AnyDifferentiable
type hides the specific underlying types.DifferenceIdentifier
type is erased byAnyHashable
. The comparisons of whether has updated is forwards to an underlying differentiable value.You can store mixed-type elements in collection that require
Differentiable
conformance by wrapping mixed-type elements inAnyDifferentiable
:
See moreextension String: Differentiable {} extension Int: Differentiable {} let source = [ AnyDifferentiable("ABC"), AnyDifferentiable(100) ] let target = [ AnyDifferentiable("ABC"), AnyDifferentiable(100), AnyDifferentiable(200) ] let changeset = StagedChangeset(source: source, target: target) print(changeset.isEmpty) // prints "false"
Declaration
Swift
public struct AnyDifferentiable : Differentiable
-
A set of changes in the sectioned collection.
Changes to the section of the linear collection should be empty.
Notice that the value of the changes represents offsets of collection not index. Since offsets are unordered, order is ignored when comparing two
See moreChangeset
s.Declaration
Swift
public struct Changeset<Collection> where Collection : Collection
-
Represents the path to a specific element in a tree of nested collections.
Note
Foundation.IndexPath
is disadvantageous in performance.Declaration
Swift
public struct ElementPath : Hashable
-
A generic differentiable section.
Arrays are can not be identify each one and comparing whether has updated from other one. Section is a generic wrapper to hold a model and elements to allow it.
See moreDeclaration
Swift
public struct Section<Model, Element> : DifferentiableSection where Model : Differentiable, Element : Differentiable