Skip to content

Commit

Permalink
Changing the CacheDelegate to not take generic funcs for setting mode…
Browse files Browse the repository at this point in the history
…ls (#41)

This is a backwards incompatible change but it should be easy to migrate.
The reason for this change is: https://bugs.swift.org/browse/SR-3038
  • Loading branch information
plivesey authored Oct 24, 2016
1 parent d6769dd commit 21bdf30
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 35 deletions.
18 changes: 12 additions & 6 deletions RocketData.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
612AB3E11CCE7C1C0034EADD /* PauseDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612AB3E01CCE7C1C0034EADD /* PauseDataProviderTests.swift */; };
612AB3E31CCE877D0034EADD /* PauseCollectionDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612AB3E21CCE877D0034EADD /* PauseCollectionDataProviderTests.swift */; };
612AB3E71CCE8AC30034EADD /* SharedCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612AB3E61CCE8AC30034EADD /* SharedCollectionTests.swift */; };
612B73621C8F9CD2005B12B1 /* ScherzoTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612B73611C8F9CD2005B12B1 /* ScherzoTestCase.swift */; };
612B73621C8F9CD2005B12B1 /* RocketDataTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612B73611C8F9CD2005B12B1 /* RocketDataTestCase.swift */; };
612B736D1C8FAF17005B12B1 /* SimpleCollectionDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612B736C1C8FAF17005B12B1 /* SimpleCollectionDataProviderTests.swift */; };
612B736F1C9079DC005B12B1 /* ConsistencyCollectionDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612B736E1C9079DC005B12B1 /* ConsistencyCollectionDataProviderTests.swift */; };
6137042E1CC91FAC008D0EBB /* WeakSharedCollectionArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6137042D1CC91FAC008D0EBB /* WeakSharedCollectionArrayTests.swift */; };
Expand All @@ -43,6 +43,7 @@
6175BEEA1C8F4BBD003A162D /* DataProviderDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6175BEE91C8F4BBD003A162D /* DataProviderDelegates.swift */; };
6192BEDB1CBFFC0A00212DC5 /* ChangeClockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6192BEDA1CBFFC0A00212DC5 /* ChangeClockTests.swift */; };
6192BEDD1CBFFDFB00212DC5 /* BatchListenerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6192BEDC1CBFFDFB00212DC5 /* BatchListenerTests.swift */; };
61B6660B1DB92CB600D9A812 /* DataModelManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61B6660A1DB92CB500D9A812 /* DataModelManagerTests.swift */; };
61FD70A91C8E1BC800DFAD2E /* ParentModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FD70A81C8E1BC800DFAD2E /* ParentModel.swift */; };
61FD70AB1C8E1BED00DFAD2E /* ChildModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61FD70AA1C8E1BED00DFAD2E /* ChildModel.swift */; };
FA5D03BE8841FEDD5A3433AD /* Pods_RocketData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F416DEBD8929CFE59C87ED /* Pods_RocketData.framework */; };
Expand Down Expand Up @@ -85,7 +86,7 @@
612AB3E01CCE7C1C0034EADD /* PauseDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PauseDataProviderTests.swift; sourceTree = "<group>"; };
612AB3E21CCE877D0034EADD /* PauseCollectionDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PauseCollectionDataProviderTests.swift; sourceTree = "<group>"; };
612AB3E61CCE8AC30034EADD /* SharedCollectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharedCollectionTests.swift; sourceTree = "<group>"; };
612B73611C8F9CD2005B12B1 /* ScherzoTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScherzoTestCase.swift; sourceTree = "<group>"; };
612B73611C8F9CD2005B12B1 /* RocketDataTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RocketDataTestCase.swift; sourceTree = "<group>"; };
612B736C1C8FAF17005B12B1 /* SimpleCollectionDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleCollectionDataProviderTests.swift; sourceTree = "<group>"; };
612B736E1C9079DC005B12B1 /* ConsistencyCollectionDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsistencyCollectionDataProviderTests.swift; sourceTree = "<group>"; };
6137042D1CC91FAC008D0EBB /* WeakSharedCollectionArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakSharedCollectionArrayTests.swift; sourceTree = "<group>"; };
Expand All @@ -100,6 +101,7 @@
6192BEDA1CBFFC0A00212DC5 /* ChangeClockTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeClockTests.swift; sourceTree = "<group>"; };
6192BEDC1CBFFDFB00212DC5 /* BatchListenerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchListenerTests.swift; sourceTree = "<group>"; };
6195AA441D413E8400F8BABB /* Pods_RocketData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Pods_RocketData.framework; path = "../../../Library/Developer/Xcode/DerivedData/RocketData-fakibhwbjgxxqqbhtroabdzpzvve/Build/Products/Debug-iphonesimulator/Pods_RocketData.framework"; sourceTree = "<group>"; };
61B6660A1DB92CB500D9A812 /* DataModelManagerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataModelManagerTests.swift; sourceTree = "<group>"; };
61FD70A81C8E1BC800DFAD2E /* ParentModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParentModel.swift; sourceTree = "<group>"; };
61FD70AA1C8E1BED00DFAD2E /* ChildModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChildModel.swift; sourceTree = "<group>"; };
93F416DEBD8929CFE59C87ED /* Pods_RocketData.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RocketData.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -177,12 +179,13 @@
612242BF1C7B85D40017B0C4 /* RocketDataTests */ = {
isa = PBXGroup;
children = (
612B73611C8F9CD2005B12B1 /* ScherzoTestCase.swift */,
612B73611C8F9CD2005B12B1 /* RocketDataTestCase.swift */,
61FD70A71C8E1BB300DFAD2E /* TestModels */,
6175BEE41C8E3120003A162D /* TestHelpers */,
61FD70A51C8E1BB300DFAD2E /* CollectionDataProviderTests */,
61FD70A61C8E1BB300DFAD2E /* DataProviderTests */,
613C430D1CA091E00080B7A3 /* ParsingHelpersTests.swift */,
61B6660A1DB92CB500D9A812 /* DataModelManagerTests.swift */,
6192BEDA1CBFFC0A00212DC5 /* ChangeClockTests.swift */,
6192BEDC1CBFFDFB00212DC5 /* BatchListenerTests.swift */,
611562DA1CC16B490001F5CE /* CollectionChangeTests.swift */,
Expand Down Expand Up @@ -477,9 +480,10 @@
6175BEE31C8E30CF003A162D /* SimpleDataProviderTests.swift in Sources */,
612AB3E31CCE877D0034EADD /* PauseCollectionDataProviderTests.swift in Sources */,
61427D061D63CD800034617E /* SmallModels.swift in Sources */,
61B6660B1DB92CB600D9A812 /* DataModelManagerTests.swift in Sources */,
61FD70AB1C8E1BED00DFAD2E /* ChildModel.swift in Sources */,
611562DB1CC16B490001F5CE /* CollectionChangeTests.swift in Sources */,
612B73621C8F9CD2005B12B1 /* ScherzoTestCase.swift in Sources */,
612B73621C8F9CD2005B12B1 /* RocketDataTestCase.swift in Sources */,
611323AA1D5BB0070046625E /* FullChildModel.swift in Sources */,
6165455E1CC7E8F600AC68C9 /* CollectionChangeHelpers.swift in Sources */,
612AB3E11CCE7C1C0034EADD /* PauseDataProviderTests.swift in Sources */,
Expand Down Expand Up @@ -605,6 +609,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = E816E0EC503C5F077273A5B3 /* Pods-RocketData.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
Expand All @@ -626,6 +631,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 997C3052192E11916F11C270 /* Pods-RocketData.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
Expand All @@ -646,7 +652,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = AC288B6D02498F01FECDAA0F /* Pods-RocketDataTests.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = RocketDataTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = LinkedIn.RocketDataTests;
Expand All @@ -659,7 +665,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = E1E495CE9B06BB69A277C55E /* Pods-RocketDataTests.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = RocketDataTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = LinkedIn.RocketDataTests;
Expand Down
4 changes: 2 additions & 2 deletions RocketData/CacheDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public protocol CacheDelegate {
- parameter cacheKey: The cache key for this model. This is always equal to the modelIdentifier.
- parameter context: A context you can pass in when saving to the cache.
*/
func setModel<T: SimpleModel>(_ model: T, forKey cacheKey: String, context: Any?)
func setModel(_ model: SimpleModel, forKey cacheKey: String, context: Any?)

/**
Given a cache key, you should retrieve a collection of type [T].
Expand All @@ -71,7 +71,7 @@ public protocol CacheDelegate {
- parameter cacheKey: The cache key for this model.
- parameter context: A context you can pass in when saving to the cache.
*/
func setCollection<T: SimpleModel>(_ collection: [T], forKey cacheKey: String, context: Any?)
func setCollection(_ collection: [SimpleModel], forKey cacheKey: String, context: Any?)

/**
Called when delete is called from the DataModelManager.
Expand Down
6 changes: 3 additions & 3 deletions RocketData/DataModelManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class DataModelManager {
- parameter updateCache: You can pass in false here if you only want to update the models in memory.
- parameter context: This context will be passed back to data provider delegates if this causes an update.
*/
open func updateModel<T: SimpleModel>(_ model: T, updateCache: Bool = true, context: Any? = nil) {
open func updateModel(_ model: SimpleModel, updateCache: Bool = true, context: Any? = nil) {
consistencyManager.updateModel(model, context: ConsistencyContextWrapper(context: context))
if updateCache, let cacheKey = model.modelIdentifier {
cacheModel(model, forKey: cacheKey, context: context)
Expand All @@ -68,7 +68,7 @@ open class DataModelManager {
- parameter updateCache: You can pass in false here if you only want to update the models in memory.
- parameter context: This context will be passed back to data provider delegates if this causes an update.
*/
open func updateModels<T: SimpleModel>(_ models: [T], updateCache: Bool = true, context: Any? = nil) {
open func updateModels(_ models: [SimpleModel], updateCache: Bool = true, context: Any? = nil) {
let batchModel = BatchUpdateModel(models: models.map { $0 as ConsistencyManagerModel })
consistencyManager.updateModel(batchModel, context: ConsistencyContextWrapper(context: context))
if updateCache {
Expand Down Expand Up @@ -108,7 +108,7 @@ open class DataModelManager {
Save a model in the cache. This simply forwards the method to the cache delegate.
The cache key you pass in here should be equal to the modelIdentifier of the model.
*/
open func cacheModel<T: SimpleModel>(_ model: T, forKey cacheKey: String, context: Any?) {
open func cacheModel(_ model: SimpleModel, forKey cacheKey: String, context: Any?) {
externalDispatchQueue.async {
self.cacheDelegate.setModel(model, forKey: cacheKey, context: context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,26 +685,24 @@ class ConsistencyCollectionDataProviderTests: RocketDataTestCase {
// MARK: Timing Tests

func testConsistencyManagerUpdateAfterSetData() {
func testDeletingModel() {
let dataProvider = CollectionDataProvider<ParentModel>(dataModelManager: DataModelManager.sharedDataManagerNoCache)
let dataProvider = CollectionDataProvider<ParentModel>(dataModelManager: DataModelManager.sharedDataManagerNoCache)

// Let's create this before we do the setData. This ensures that this change happened before the setData.
let contextWrapper = ConsistencyContextWrapper(context: nil)
// Let's create this before we do the setData. This ensures that this change happened before the setData.
let contextWrapper = ConsistencyContextWrapper(context: nil)

let initialModel = ParentModel(id: 1, name: "initial", requiredChild: ChildModel(), otherChildren: [])
let newModel = ParentModel(id: 1, name: "new", requiredChild: ChildModel(), otherChildren: [])
let initialModel = ParentModel(id: 1, name: "initial", requiredChild: ChildModel(), otherChildren: [])
let newModel = ParentModel(id: 1, name: "new", requiredChild: ChildModel(), otherChildren: [])

let delegate = ClosureCollectionDataProviderDelegate() { (collectionChanges, context) in
XCTFail()
}
dataProvider.delegate = delegate
let delegate = ClosureCollectionDataProviderDelegate() { (collectionChanges, context) in
XCTFail()
}
dataProvider.delegate = delegate

dataProvider.setData([initialModel], cacheKey: nil, context: "wrong")
// This uses a date before the setData, so should be a no-op
DataModelManager.sharedDataManagerNoCache.consistencyManager.updateModel(newModel, context: contextWrapper)
dataProvider.setData([initialModel], cacheKey: nil, context: "wrong")
// This uses a date before the setData, so should be a no-op
DataModelManager.sharedDataManagerNoCache.consistencyManager.updateModel(newModel, context: contextWrapper)

waitForConsistencyManagerToFlush(DataModelManager.sharedDataManagerNoCache.consistencyManager)
}
waitForConsistencyManagerToFlush(DataModelManager.sharedDataManagerNoCache.consistencyManager)
}

// MARK: Projection Tests
Expand Down
Loading

0 comments on commit 21bdf30

Please sign in to comment.