From 3e082d5ed4e4f46924650f6beaa5ba5bc5e7d11e Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Wed, 20 Sep 2017 00:45:38 +0900 Subject: [PATCH] queryBuilders for list monitors --- Sources/CoreStore+Observing.swift | 37 +++++++++++++++++++ Sources/DataStack+Observing.swift | 37 +++++++++++++++++++ Sources/UnsafeDataTransaction+Observing.swift | 37 +++++++++++++++++++ 3 files changed, 111 insertions(+) diff --git a/Sources/CoreStore+Observing.swift b/Sources/CoreStore+Observing.swift index d785255..546f740 100644 --- a/Sources/CoreStore+Observing.swift +++ b/Sources/CoreStore+Observing.swift @@ -67,6 +67,12 @@ public extension CoreStore { return self.defaultStack.monitorList(from, fetchClauses) } + // TODO: docs + public static func monitorList(_ clauseChain: B) -> ListMonitor { + + return self.defaultStack.monitorList(clauseChain.from, clauseChain.fetchClauses) + } + /** Using the `defaultStack`, asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed. @@ -91,6 +97,16 @@ public extension CoreStore { self.defaultStack.monitorList(createAsynchronously: createAsynchronously, from, fetchClauses) } + // TODO: docs + public static func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { + + self.defaultStack.monitorList( + createAsynchronously: createAsynchronously, + clauseChain.from, + clauseChain.fetchClauses + ) + } + /** Using the `defaultStack`, creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. @@ -117,6 +133,16 @@ public extension CoreStore { return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses) } + // TODO: docs + public static func monitorSectionedList(_ clauseChain: B) -> ListMonitor { + + return self.defaultStack.monitorSectionedList( + clauseChain.from, + clauseChain.sectionBy, + clauseChain.fetchClauses + ) + } + /** Using the `defaultStack`, asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed. @@ -142,4 +168,15 @@ public extension CoreStore { self.defaultStack.monitorSectionedList(createAsynchronously: createAsynchronously, from, sectionBy, fetchClauses) } + + // TODO: docs + public static func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { + + self.defaultStack.monitorSectionedList( + createAsynchronously: createAsynchronously, + clauseChain.from, + clauseChain.sectionBy, + clauseChain.fetchClauses + ) + } } diff --git a/Sources/DataStack+Observing.swift b/Sources/DataStack+Observing.swift index 7777e82..1c08c18 100644 --- a/Sources/DataStack+Observing.swift +++ b/Sources/DataStack+Observing.swift @@ -88,6 +88,12 @@ public extension DataStack { ) } + // TODO: docs + public func monitorList(_ clauseChain: B) -> ListMonitor { + + return self.monitorList(clauseChain.from, clauseChain.fetchClauses) + } + /** Asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed. @@ -130,6 +136,16 @@ public extension DataStack { ) } + // TODO: docs + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { + + self.monitorList( + createAsynchronously: createAsynchronously, + clauseChain.from, + clauseChain.fetchClauses + ) + } + /** Creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. @@ -174,6 +190,16 @@ public extension DataStack { ) } + // TODO: docs + public func monitorSectionedList(_ clauseChain: B) -> ListMonitor { + + return self.monitorSectionedList( + clauseChain.from, + clauseChain.sectionBy, + clauseChain.fetchClauses + ) + } + /** Asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed. @@ -218,4 +244,15 @@ public extension DataStack { createAsynchronously: createAsynchronously ) } + + // TODO: docs + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { + + self.monitorSectionedList( + createAsynchronously: createAsynchronously, + clauseChain.from, + clauseChain.sectionBy, + clauseChain.fetchClauses + ) + } } diff --git a/Sources/UnsafeDataTransaction+Observing.swift b/Sources/UnsafeDataTransaction+Observing.swift index 181f28b..9a9b861 100644 --- a/Sources/UnsafeDataTransaction+Observing.swift +++ b/Sources/UnsafeDataTransaction+Observing.swift @@ -83,6 +83,12 @@ public extension UnsafeDataTransaction { ) } + // TODO: docs + public func monitorList(_ clauseChain: B) -> ListMonitor { + + return self.monitorList(clauseChain.from, clauseChain.fetchClauses) + } + /** Asynchronously creates a `ListMonitor` for a list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed. @@ -121,6 +127,16 @@ public extension UnsafeDataTransaction { ) } + // TODO: docs + public func monitorList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { + + self.monitorList( + createAsynchronously: createAsynchronously, + clauseChain.from, + clauseChain.fetchClauses + ) + } + /** Creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. @@ -160,6 +176,16 @@ public extension UnsafeDataTransaction { ) } + // TODO: docs + public func monitorSectionedList(_ clauseChain: B) -> ListMonitor { + + return self.monitorSectionedList( + clauseChain.from, + clauseChain.sectionBy, + clauseChain.fetchClauses + ) + } + /** Asynchronously creates a `ListMonitor` for a sectioned list of `DynamicObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed. @@ -199,4 +225,15 @@ public extension UnsafeDataTransaction { createAsynchronously: createAsynchronously ) } + + // TODO: docs + public func monitorSectionedList(createAsynchronously: @escaping (ListMonitor) -> Void, _ clauseChain: B) { + + self.monitorSectionedList( + createAsynchronously: createAsynchronously, + clauseChain.from, + clauseChain.sectionBy, + clauseChain.fetchClauses + ) + } }