simplification
This commit is contained in:
parent
2c3e97779d
commit
d7f6e6cd47
|
@ -32,6 +32,7 @@
|
||||||
D0CF8A0F1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CF8A0B1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift */; settings = {ASSET_TAGS = (); }; };
|
D0CF8A0F1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CF8A0B1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
D0CF8A101BE2AC1700EC9F12 /* CoreDataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CF8A0C1BE2AC1700EC9F12 /* CoreDataExtensions.swift */; settings = {ASSET_TAGS = (); }; };
|
D0CF8A101BE2AC1700EC9F12 /* CoreDataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CF8A0C1BE2AC1700EC9F12 /* CoreDataExtensions.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
D0CF8A201BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CF8A1F1BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift */; settings = {ASSET_TAGS = (); }; };
|
D0CF8A201BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CF8A1F1BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
|
D0CF8A221BE2D65300EC9F12 /* MeteorCollectionChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CF8A211BE2D65300EC9F12 /* MeteorCollectionChange.swift */; settings = {ASSET_TAGS = (); }; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
@ -95,6 +96,7 @@
|
||||||
D0CF8A0B1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeteorCoreDataCollection.swift; sourceTree = "<group>"; };
|
D0CF8A0B1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeteorCoreDataCollection.swift; sourceTree = "<group>"; };
|
||||||
D0CF8A0C1BE2AC1700EC9F12 /* CoreDataExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataExtensions.swift; sourceTree = "<group>"; };
|
D0CF8A0C1BE2AC1700EC9F12 /* CoreDataExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataExtensions.swift; sourceTree = "<group>"; };
|
||||||
D0CF8A1F1BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeteorCoreDataTableViewController.swift; sourceTree = "<group>"; };
|
D0CF8A1F1BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeteorCoreDataTableViewController.swift; sourceTree = "<group>"; };
|
||||||
|
D0CF8A211BE2D65300EC9F12 /* MeteorCollectionChange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeteorCollectionChange.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -193,6 +195,7 @@
|
||||||
D0CF8A0A1BE2AC1700EC9F12 /* MeteorCoreDataStack.swift */,
|
D0CF8A0A1BE2AC1700EC9F12 /* MeteorCoreDataStack.swift */,
|
||||||
D0CF8A0B1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift */,
|
D0CF8A0B1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift */,
|
||||||
D0CF8A1F1BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift */,
|
D0CF8A1F1BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift */,
|
||||||
|
D0CF8A211BE2D65300EC9F12 /* MeteorCollectionChange.swift */,
|
||||||
D0CF8A0C1BE2AC1700EC9F12 /* CoreDataExtensions.swift */,
|
D0CF8A0C1BE2AC1700EC9F12 /* CoreDataExtensions.swift */,
|
||||||
);
|
);
|
||||||
name = MeteorCoreData;
|
name = MeteorCoreData;
|
||||||
|
@ -364,6 +367,7 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
D0CF8A201BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift in Sources */,
|
D0CF8A201BE2CA1800EC9F12 /* MeteorCoreDataTableViewController.swift in Sources */,
|
||||||
|
D0CF8A221BE2D65300EC9F12 /* MeteorCollectionChange.swift in Sources */,
|
||||||
D0CF8A0F1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift in Sources */,
|
D0CF8A0F1BE2AC1700EC9F12 /* MeteorCoreDataCollection.swift in Sources */,
|
||||||
D0CF8A101BE2AC1700EC9F12 /* CoreDataExtensions.swift in Sources */,
|
D0CF8A101BE2AC1700EC9F12 /* CoreDataExtensions.swift in Sources */,
|
||||||
D02A72101BBEFCD300940C17 /* DDPClient.swift in Sources */,
|
D02A72101BBEFCD300940C17 /* DDPClient.swift in Sources */,
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
//
|
||||||
|
// MeteorCollectionChange
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
struct MeteorCollectionChange: Hashable {
|
||||||
|
var id:String
|
||||||
|
var collection:String
|
||||||
|
var fields:NSDictionary?
|
||||||
|
var cleared:[String]?
|
||||||
|
var hashValue:Int {
|
||||||
|
var hash = "\(id.hashValue)\(collection.hashValue)"
|
||||||
|
if let _ = fields { hash += "\(fields!.hashValue)" }
|
||||||
|
if let _ = cleared {
|
||||||
|
for value in cleared! {
|
||||||
|
hash += "\(value.hashValue)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hash.hashValue
|
||||||
|
}
|
||||||
|
|
||||||
|
init(id:String, collection:String, fields:NSDictionary?, cleared:[String]?){
|
||||||
|
self.id = id
|
||||||
|
self.collection = collection
|
||||||
|
self.fields = fields
|
||||||
|
self.cleared = cleared
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ==(lhs:MeteorCollectionChange, rhs:MeteorCollectionChange) -> Bool {
|
||||||
|
return lhs.hashValue == rhs.hashValue
|
||||||
|
}
|
|
@ -4,6 +4,6 @@ import Foundation
|
||||||
public class MeteorCoreData {
|
public class MeteorCoreData {
|
||||||
static let stack:MeteorCoreDataStack = {
|
static let stack:MeteorCoreDataStack = {
|
||||||
print("Initializing MeteorCoreDataStack")
|
print("Initializing MeteorCoreDataStack")
|
||||||
return MeteorCoreDataStack()
|
return MeteorCoreDataStackPersisted()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
|
@ -8,50 +8,10 @@ public protocol MeteorCoreDataCollectionDelegate {
|
||||||
func document(willBeUpdatedWith fields:NSDictionary?, cleared:[String]?, forObject object:NSManagedObject) -> NSManagedObject
|
func document(willBeUpdatedWith fields:NSDictionary?, cleared:[String]?, forObject object:NSManagedObject) -> NSManagedObject
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// MeteorCollectionChange
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
struct MeteorCollectionChange: Hashable {
|
|
||||||
var id:String
|
|
||||||
var collection:String
|
|
||||||
var fields:NSDictionary?
|
|
||||||
var cleared:[String]?
|
|
||||||
var hashValue:Int {
|
|
||||||
var hash = "\(id.hashValue)\(collection.hashValue)"
|
|
||||||
if let _ = fields { hash += "\(fields!.hashValue)" }
|
|
||||||
if let _ = cleared {
|
|
||||||
for value in cleared! {
|
|
||||||
hash += "\(value.hashValue)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hash.hashValue
|
|
||||||
}
|
|
||||||
|
|
||||||
init(id:String, collection:String, fields:NSDictionary?, cleared:[String]?){
|
|
||||||
self.id = id
|
|
||||||
self.collection = collection
|
|
||||||
self.fields = fields
|
|
||||||
self.cleared = cleared
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ==(lhs:MeteorCollectionChange, rhs:MeteorCollectionChange) -> Bool {
|
|
||||||
return lhs.hashValue == rhs.hashValue
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// End Meteor Collection Change
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
public class MeteorCoreDataCollection:Collection {
|
public class MeteorCoreDataCollection:Collection {
|
||||||
|
|
||||||
private let entityName:String
|
private let entityName:String
|
||||||
private let stack = MeteorCoreData.stack
|
private let stack:MeteorCoreDataCollectionStack
|
||||||
private var changeLog = [Int:MeteorCollectionChange]()
|
private var changeLog = [Int:MeteorCollectionChange]()
|
||||||
|
|
||||||
private lazy var mainContext:NSManagedObjectContext = { return self.stack.mainContext }()
|
private lazy var mainContext:NSManagedObjectContext = { return self.stack.mainContext }()
|
||||||
|
@ -61,6 +21,13 @@ public class MeteorCoreDataCollection:Collection {
|
||||||
|
|
||||||
public init(collectionName:String, entityName:String) {
|
public init(collectionName:String, entityName:String) {
|
||||||
self.entityName = entityName
|
self.entityName = entityName
|
||||||
|
self.stack = MeteorCoreData.stack
|
||||||
|
super.init(name: collectionName)
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(collectionName:String, entityName:String, inMemory:Bool) {
|
||||||
|
self.entityName = entityName
|
||||||
|
self.stack = MeteorCoreData.stack
|
||||||
super.init(name: collectionName)
|
super.init(name: collectionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,13 @@ import Foundation
|
||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
|
|
||||||
public class MeteorCoreDataStack:NSObject {
|
public protocol MeteorCoreDataCollectionStack {
|
||||||
|
var mainContext: NSManagedObjectContext { get }
|
||||||
|
var backgroundContext: NSManagedObjectContext { get }
|
||||||
|
var managedObjectContext:NSManagedObjectContext { get }
|
||||||
|
}
|
||||||
|
|
||||||
|
class MeteorCoreDataStackPersisted:NSObject, MeteorCoreDataCollectionStack {
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
Loading…
Reference in New Issue