Skip to content

Commit

Permalink
cleanup & test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-stripe committed Dec 12, 2017
1 parent bcc86d6 commit 6e16ae3
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 275 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ matrix:
- set -o pipefail;
- open -a "simulator" --args -CurrentDeviceUDID "$UUID"
- xcodebuild -scheme Dwifft -destination "id=$UUID" test | xcpretty
- xcodebuild -scheme Dwifft-macOS test | xcpretty

env:
global:
secure: pUV8Ccwq1FWO8PxTHPQ3qZDUDhjNOisNVRyrziYR8x0ZQYjmVmnaLKaOHFP8co6rhBlFqReKUjoFYgRqP5QK1EkD6lqSZfnkrWqnZuLDNy0sn3/+4sLtvqAhBroAfjmmvb5GpY+Kkqfz8Lhdu6+1Z/a5xPhqNeDO3aDpa2vdBztb2qLIZnf2g8NFLOoNuR+ula868nIm858LCN1sqLp9PhV4CGaMsFx7ZFaX1yEQbwNb8+85+U2HIHqjZ62u9KZ4lA1d58VVDGj2f7ObKkC+pjiuknljy5bvRVvg5pttXggJracFgMqouwwQFFCV3nFYSDS6h7ZIjUvbyMrqBN+u32RmtqVLp1by1JvRXSeemJ3HxtZGLbq7rff4zWXyYbelT6sR6J1tWIubRo5v3sXc8E1kurqKkcPqJdG4jqiUXOau2oSHhf7WCRwa0KNfvaQuMhm0Onnsi9tW2MzGieumscfuFIJsXJdXnac7jQUVb571GfxMrDeJ9v2GOPcbnlM8cttBFAw4IoINV6teKITUW6T8RpeDXzfQyxDDQaV0M1ZTab1Tj/f4EYDAXKfZ+QquWK3bgXJhxKghXIskZLdDhYMyP55T6QxLZY9wD2CxLrEbEhDQCEb+7R2LmIC95Rlku+W92b8eWAqNxf+vV7QRqBb/sV9w2mlxmmezYTP5VAs=
4 changes: 0 additions & 4 deletions Dwifft-macOS/Dwifft_macOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ FOUNDATION_EXPORT double Dwifft_macOSVersionNumber;

//! Project version string for Dwifft_macOS.
FOUNDATION_EXPORT const unsigned char Dwifft_macOSVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <Dwifft_macOS/PublicHeader.h>


12 changes: 12 additions & 0 deletions Dwifft.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
041EBBB11B8967C300E113B3 /* Dwifft.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041EBBAE1B8967C300E113B3 /* Dwifft.swift */; };
041EBBB21B8967C300E113B3 /* Dwifft+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041EBBAF1B8967C300E113B3 /* Dwifft+UIKit.swift */; };
041EBBB31B8967C300E113B3 /* Dwifft+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041EBBAF1B8967C300E113B3 /* Dwifft+UIKit.swift */; };
044079181FDF75FF00DDB952 /* AbstractDiffCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 044079171FDF75FF00DDB952 /* AbstractDiffCalculator.swift */; };
044079191FDF75FF00DDB952 /* AbstractDiffCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 044079171FDF75FF00DDB952 /* AbstractDiffCalculator.swift */; };
0440791A1FDF75FF00DDB952 /* AbstractDiffCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 044079171FDF75FF00DDB952 /* AbstractDiffCalculator.swift */; };
0486A2651EA0A5B600D8093E /* SectionedValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0486A2641EA0A5B600D8093E /* SectionedValues.swift */; };
0486A2661EA0A64900D8093E /* SectionedValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0486A2641EA0A5B600D8093E /* SectionedValues.swift */; };
04AC329F1E88AEB000EF63DD /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04AC329E1E88AEB000EF63DD /* SwiftCheck.framework */; };
04CEEB8F1FDF787B00C17562 /* AbstractDiffCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 044079171FDF75FF00DDB952 /* AbstractDiffCalculator.swift */; };
04CEEB901FDF787D00C17562 /* AbstractDiffCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 044079171FDF75FF00DDB952 /* AbstractDiffCalculator.swift */; };
380FFA411F7BF2E000AEF983 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38D317731F7BF1E400A15CD7 /* SwiftCheck.framework */; };
382DEF461F487396007A8FD2 /* Dwifft_macOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 382DEF441F487395007A8FD2 /* Dwifft_macOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
382DEF4B1F487519007A8FD2 /* Dwifft.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041EBBAE1B8967C300E113B3 /* Dwifft.swift */; };
Expand Down Expand Up @@ -74,6 +79,7 @@
041EBBA41B89679200E113B3 /* DwifftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DwifftTests.swift; sourceTree = "<group>"; };
041EBBAE1B8967C300E113B3 /* Dwifft.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dwifft.swift; sourceTree = "<group>"; };
041EBBAF1B8967C300E113B3 /* Dwifft+UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dwifft+UIKit.swift"; sourceTree = "<group>"; };
044079171FDF75FF00DDB952 /* AbstractDiffCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AbstractDiffCalculator.swift; sourceTree = "<group>"; };
0486A2641EA0A5B600D8093E /* SectionedValues.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionedValues.swift; sourceTree = "<group>"; };
04AC329E1E88AEB000EF63DD /* SwiftCheck.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftCheck.framework; path = Carthage/Build/iOS/SwiftCheck.framework; sourceTree = SOURCE_ROOT; };
380FFA421F7C072D00AEF983 /* macOS Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "macOS Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -155,6 +161,7 @@
041EBB971B89679200E113B3 /* Dwifft.h */,
041EBBAE1B8967C300E113B3 /* Dwifft.swift */,
0486A2641EA0A5B600D8093E /* SectionedValues.swift */,
044079171FDF75FF00DDB952 /* AbstractDiffCalculator.swift */,
041EBBAF1B8967C300E113B3 /* Dwifft+UIKit.swift */,
382DEF4A1F4873F9007A8FD2 /* Dwifft+AppKit.swift */,
041EBB951B89679200E113B3 /* Supporting Files */,
Expand Down Expand Up @@ -451,6 +458,7 @@
041EBBB01B8967C300E113B3 /* Dwifft.swift in Sources */,
0486A2651EA0A5B600D8093E /* SectionedValues.swift in Sources */,
041EBBB21B8967C300E113B3 /* Dwifft+UIKit.swift in Sources */,
044079181FDF75FF00DDB952 /* AbstractDiffCalculator.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -459,6 +467,7 @@
buildActionMask = 2147483647;
files = (
0486A2661EA0A64900D8093E /* SectionedValues.swift in Sources */,
04CEEB8F1FDF787B00C17562 /* AbstractDiffCalculator.swift in Sources */,
041EBBB11B8967C300E113B3 /* Dwifft.swift in Sources */,
041EBBA51B89679200E113B3 /* DwifftTests.swift in Sources */,
041EBBB31B8967C300E113B3 /* Dwifft+UIKit.swift in Sources */,
Expand All @@ -472,6 +481,7 @@
382DEF4B1F487519007A8FD2 /* Dwifft.swift in Sources */,
382DEF4C1F48751B007A8FD2 /* SectionedValues.swift in Sources */,
382DEF4D1F48751C007A8FD2 /* Dwifft+AppKit.swift in Sources */,
0440791A1FDF75FF00DDB952 /* AbstractDiffCalculator.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -480,6 +490,7 @@
buildActionMask = 2147483647;
files = (
38E5B5EB1F7BDBC700F33285 /* DwifftTests-macOS.swift in Sources */,
04CEEB901FDF787D00C17562 /* AbstractDiffCalculator.swift in Sources */,
38E5B5EA1F7BDBBB00F33285 /* Dwifft+AppKit.swift in Sources */,
38E5B5D61F7BDB5400F33285 /* SectionedValues.swift in Sources */,
38E5B5D71F7BDB5400F33285 /* Dwifft.swift in Sources */,
Expand All @@ -493,6 +504,7 @@
94783CB71EFBA25300841579 /* Dwifft+UIKit.swift in Sources */,
94783CB61EFBA25300841579 /* SectionedValues.swift in Sources */,
94783CB51EFBA25300841579 /* Dwifft.swift in Sources */,
044079191FDF75FF00DDB952 /* AbstractDiffCalculator.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
93 changes: 93 additions & 0 deletions Dwifft/AbstractDiffCalculator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// AbstractDiffCalculator.swift
// Dwifft
//
// Created by Jack Flintermann on 12/11/17.
// Copyright © 2017 jflinter. All rights reserved.
//

import Foundation

/// A parent class for all diff calculators. Don't use it directly.
public class AbstractDiffCalculator<Section: Equatable, Value: Equatable> {

internal init(initialSectionedValues: SectionedValues<Section, Value>) {
self._sectionedValues = initialSectionedValues
}

/// The number of sections in the diff calculator. Return this inside
/// `numberOfSections(in: tableView)` or `numberOfSections(in: collectionView)`.
/// Don't implement that method any other way (see the docs for `numberOfObjects(inSection:)`
/// for more context).
public final func numberOfSections() -> Int {
return self.sectionedValues.sections.count
}

/// The section at a given index. If you implement `tableView:titleForHeaderInSection` or
/// `collectionView:viewForSupplementaryElementOfKind:atIndexPath`, you can use this
/// method to get information about that section out of Dwifft.
///
/// - Parameter forSection: the index of the section you care about.
/// - Returns: the Section at that index.
public final func value(forSection: Int) -> Section {
return self.sectionedValues[forSection].0
}


/// The, uh, number of objects in a given section. Use this to implement
/// `UITableViewDataSource.numberOfRowsInSection:` or `UICollectionViewDataSource.numberOfItemsInSection:`.
/// Seriously, don't implement that method any other way - there is some subtle timing stuff
/// around when this value should change in order to satisfy `UITableView`/`UICollectionView`'s internal
/// assertions, that Dwifft knows how to handle correctly. Read the source for
/// Dwifft+UIKit.swift if you don't believe me/want to learn more.
///
/// - Parameter section: a section of your table/collection view
/// - Returns: the number of objects in that section.
public final func numberOfObjects(inSection section: Int) -> Int {
return self.sectionedValues[section].1.count
}


/// The value at a given index path. Use this to implement
/// `UITableViewDataSource.cellForRowAtIndexPath` or `UICollectionViewDataSource.cellForItemAtIndexPath`.
///
/// - Parameter indexPath: the index path you are interested in
/// - Returns: the thing at that index path
public final func value(atIndexPath indexPath: IndexPath) -> Value {
#if os(iOS) || os(tvOS)
let row = indexPath.row
#endif
#if os(macOS)
let row = indexPath.item
#endif
return self.sectionedValues[indexPath.section].1[row]
}


/// Set this variable to automatically trigger the correct section/row/item insertion/deletions
/// on your table/collection view.
public final var sectionedValues: SectionedValues<Section, Value> {
get {
return _sectionedValues
}
set {
let oldSectionedValues = sectionedValues
let newSectionedValues = newValue
let diff = Dwifft.diff(lhs: oldSectionedValues, rhs: newSectionedValues)
if (diff.count > 0) {
self.processChanges(newState: newSectionedValues, diff: diff)
}
}
}

internal static func buildSectionedValues(values: [Value], sectionIndex: Int) -> SectionedValues<Int, Value> {
let firstRows = (0..<sectionIndex).map { ($0, [Value]()) }
return SectionedValues(firstRows + [(sectionIndex, values)])
}

// UITableView and UICollectionView both perform assertions on the *current* number of rows/items before performing any updates. As such, the `sectionedValues` property must be backed by an internal value that does not change until *after* `beginUpdates`/`performBatchUpdates` has been called.
internal final var _sectionedValues: SectionedValues<Section, Value>
internal func processChanges(newState: SectionedValues<Section, Value>, diff: [SectionedDiffStep<Section, Value>]){
fatalError("override me")
}
}
Loading

0 comments on commit 6e16ae3

Please sign in to comment.