-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #709 from apollographql/rm/public-promise
Remove Public Promise
- Loading branch information
Showing
16 changed files
with
525 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// DispatchQueue+Optional.swift | ||
// Apollo | ||
// | ||
// Created by Ellen Shapiro on 8/13/19. | ||
// Copyright © 2019 Apollo GraphQL. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension DispatchQueue { | ||
|
||
static func apollo_performAsyncIfNeeded(on callbackQueue: DispatchQueue?, action: @escaping () -> Void) { | ||
if let callbackQueue = callbackQueue { | ||
// A callback queue was provided, perform the action on that queue | ||
callbackQueue.async { | ||
action() | ||
} | ||
} else { | ||
// Perform the action on the current queue | ||
action() | ||
} | ||
} | ||
|
||
static func apollo_returnResultAsyncIfNeeded<T>(on callbackQueue: DispatchQueue?, action: ((Result<T, Error>) -> Void)?, result: Result<T, Error>) { | ||
guard let action = action else { | ||
return | ||
} | ||
|
||
self.apollo_performAsyncIfNeeded(on: callbackQueue) { | ||
action(result) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
public protocol NormalizedCache { | ||
|
||
/// Loads records corresponding to the given keys. | ||
/// - returns: A promise that fulfills with an array, with each index containing either the | ||
/// record corresponding to the key at that index or nil if not found. | ||
func loadRecords(forKeys keys: [CacheKey]) -> Promise<[Record?]> | ||
|
||
/// | ||
/// - Parameters: | ||
/// - keys: The cache keys to load data for | ||
/// - callbackQueue: [optional] An alternate queue to fire the completion closure on. If nil, will fire on the current queue. | ||
/// - completion: A completion closure to fire when the load has completed. If successful, will contain an array. Each index will contain either the record corresponding to the key at the same index in the passed-in array of cache keys, or nil if that record was not found. | ||
func loadRecords(forKeys keys: [CacheKey], | ||
callbackQueue: DispatchQueue?, | ||
completion: @escaping (Result<[Record?], Error>) -> Void) | ||
|
||
/// Merges a set of records into the cache. | ||
/// - returns: A promise that fulfills with a set of keys corresponding to *fields* that have | ||
/// changed (i.e. QUERY_ROOT.Foo.myField). These are the same type of keys as are | ||
/// returned by RecordSet.merge(records:). | ||
func merge(records: RecordSet) -> Promise<Set<CacheKey>> | ||
/// | ||
/// - Parameters: | ||
/// - records: The set of records to merge. | ||
/// - callbackQueue: [optional] An alternate queue to fire the completion closure on. If nil, will fire on the current queue. | ||
/// - completion: A completion closure to fire when the merge has completed. If successful, will contain a set of keys corresponding to *fields* that have changed (i.e. QUERY_ROOT.Foo.myField). These are the same type of keys as are returned by RecordSet.merge(records:). | ||
func merge(records: RecordSet, | ||
callbackQueue: DispatchQueue?, | ||
completion: @escaping (Result<Set<CacheKey>, Error>) -> Void) | ||
|
||
// Clears all records | ||
func clear() -> Promise<Void> | ||
/// | ||
/// - Parameters: | ||
/// - callbackQueue: [optional] An alternate queue to fire the completion closure on. If nil, will fire on the current queue. | ||
/// - completion: [optional] A completion closure to fire when the clear function has completed. | ||
func clear(callbackQueue: DispatchQueue?, | ||
completion: ((Result<Void, Error>) -> Void)?) | ||
} | ||
|
Oops, something went wrong.