Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
playing with firestore
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Martin committed Nov 30, 2018
1 parent 46fa9d7 commit 5821ffa
Show file tree
Hide file tree
Showing 3,237 changed files with 643,950 additions and 3,769 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
49 changes: 49 additions & 0 deletions Example/MJSwiftCore.xcodeproj/project.pbxproj
Expand Up @@ -37,7 +37,10 @@
D219D7161FCC2E4300D91CED /* UIKitMVPItemDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D219D70D1FCC2E4300D91CED /* UIKitMVPItemDetailView.swift */; };
D219D7171FCC2E4300D91CED /* UIKitMVPItemDetailPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D219D70E1FCC2E4300D91CED /* UIKitMVPItemDetailPresenter.swift */; };
D22A0BA62035CD580026068F /* TestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22A0BA52035CD580026068F /* TestHelper.swift */; };
D22C0B1D21AEC80800F82D63 /* FirestoreDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22C0B1C21AEC80800F82D63 /* FirestoreDataSource.swift */; };
D22C0B1F21AEE7F200F82D63 /* Firestore+Future.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22C0B1E21AEE7F200F82D63 /* Firestore+Future.swift */; };
D2B7A6BD2105C31C0022B46C /* ItemAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B7A6BC2105C31C0022B46C /* ItemAssembly.swift */; };
D2C4AD5721B134AB0024D6BD /* ObserveDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2C4AD5621B134AB0024D6BD /* ObserveDataSource.swift */; };
D2D9FB5B203DE7E20069AE74 /* Future+InitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB5A203DE7E20069AE74 /* Future+InitTests.swift */; };
D2D9FB5D203DEC8A0069AE74 /* Future+SetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB5C203DEC8A0069AE74 /* Future+SetTests.swift */; };
D2D9FB63203DEC990069AE74 /* MJFuturePerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D9FB5F203DEC990069AE74 /* MJFuturePerformanceTests.swift */; };
Expand Down Expand Up @@ -100,7 +103,10 @@
D219D70E1FCC2E4300D91CED /* UIKitMVPItemDetailPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIKitMVPItemDetailPresenter.swift; sourceTree = "<group>"; };
D22A0B9E2035C91F0026068F /* MJSwiftCore_Example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MJSwiftCore_Example-Bridging-Header.h"; sourceTree = "<group>"; };
D22A0BA52035CD580026068F /* TestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelper.swift; sourceTree = "<group>"; };
D22C0B1C21AEC80800F82D63 /* FirestoreDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirestoreDataSource.swift; sourceTree = "<group>"; };
D22C0B1E21AEE7F200F82D63 /* Firestore+Future.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Firestore+Future.swift"; sourceTree = "<group>"; };
D2B7A6BC2105C31C0022B46C /* ItemAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemAssembly.swift; sourceTree = "<group>"; };
D2C4AD5621B134AB0024D6BD /* ObserveDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObserveDataSource.swift; sourceTree = "<group>"; };
D2D9FB5A203DE7E20069AE74 /* Future+InitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Future+InitTests.swift"; sourceTree = "<group>"; };
D2D9FB5C203DEC8A0069AE74 /* Future+SetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Future+SetTests.swift"; sourceTree = "<group>"; };
D2D9FB5F203DEC990069AE74 /* MJFuturePerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MJFuturePerformanceTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -159,6 +165,9 @@
D219D6CE1FCC2E2D00D91CED /* Core */,
D219D6FF1FCC2E4300D91CED /* Screens */,
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
D2C4AD5621B134AB0024D6BD /* ObserveDataSource.swift */,
D22C0B1E21AEE7F200F82D63 /* Firestore+Future.swift */,
D22C0B1C21AEC80800F82D63 /* FirestoreDataSource.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
Expand Down Expand Up @@ -426,6 +435,7 @@
607FACCD1AFB9204008FA782 /* Frameworks */,
607FACCE1AFB9204008FA782 /* Resources */,
03C9AEE3DA12D5762EDCE73E /* [CP] Embed Pods Frameworks */,
52E83EA0F40EBDEAFFB6CE1C /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -527,34 +537,70 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-MJSwiftCore_Example/Pods-MJSwiftCore_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/BoringSSL/openssl.framework",
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework",
"${BUILT_PRODUCTS_DIR}/MJCocoaCore/MJCocoaCore.framework",
"${BUILT_PRODUCTS_DIR}/MJObjection/MJObjection.framework",
"${BUILT_PRODUCTS_DIR}/MJSwiftCore/MJSwiftCore.framework",
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
"${BUILT_PRODUCTS_DIR}/PromisesSwift/Promises.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework",
"${BUILT_PRODUCTS_DIR}/Realm/Realm.framework",
"${BUILT_PRODUCTS_DIR}/RealmSwift/RealmSwift.framework",
"${BUILT_PRODUCTS_DIR}/Swinject/Swinject.framework",
"${BUILT_PRODUCTS_DIR}/gRPC-C++/grpcpp.framework",
"${BUILT_PRODUCTS_DIR}/gRPC-Core/grpc.framework",
"${BUILT_PRODUCTS_DIR}/leveldb-library/leveldb.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kingfisher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJCocoaCore.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJObjection.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJSwiftCore.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Promises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RealmSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Swinject.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/grpcpp.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/grpc.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/leveldb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MJSwiftCore_Example/Pods-MJSwiftCore_Example-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
52E83EA0F40EBDEAFFB6CE1C /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-MJSwiftCore_Example/Pods-MJSwiftCore_Example-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/FirebaseFirestore/gRPCCertificates.bundle",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/gRPCCertificates.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MJSwiftCore_Example/Pods-MJSwiftCore_Example-resources.sh\"\n";
showEnvVarsInLog = 0;
};
D655CECD9D2D96C417B8E013 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -603,6 +649,7 @@
D219D6FB1FCC2E2D00D91CED /* Item.swift in Sources */,
D219D6F11FCC2E2D00D91CED /* NetworkAssembly.swift in Sources */,
D219D7171FCC2E4300D91CED /* UIKitMVPItemDetailPresenter.swift in Sources */,
D22C0B1F21AEE7F200F82D63 /* Firestore+Future.swift in Sources */,
D219D6EE1FCC2E2D00D91CED /* RealmAssembly.swift in Sources */,
D219D6F91FCC2E2D00D91CED /* ItemMapper.swift in Sources */,
D219D6F21FCC2E2D00D91CED /* UnauthorizedStatusCodeRetrier.swift in Sources */,
Expand All @@ -616,6 +663,8 @@
D219D7151FCC2E4300D91CED /* UIKitMVPItemDetailViewController.swift in Sources */,
D219D7141FCC2E4300D91CED /* UIKitMVPItemListPresenter.swift in Sources */,
D219D6F31FCC2E2D00D91CED /* OAuth2RetryHandler.swift in Sources */,
D2C4AD5721B134AB0024D6BD /* ObserveDataSource.swift in Sources */,
D22C0B1D21AEC80800F82D63 /* FirestoreDataSource.swift in Sources */,
D219D6ED1FCC2E2D00D91CED /* AppAssembler.swift in Sources */,
D219D6F61FCC2E2D00D91CED /* RealmItem.swift in Sources */,
D219D7161FCC2E4300D91CED /* UIKitMVPItemDetailView.swift in Sources */,
Expand Down
116 changes: 116 additions & 0 deletions Example/MJSwiftCore/Firestore+Future.swift
@@ -0,0 +1,116 @@
//
// Copyright 2018 Mobile Jazz SL
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import FirebaseFirestore
import MJSwiftCore

extension FirebaseFirestore.Query {
public func get(source: FirestoreSource = .default) -> Future<QuerySnapshot> {
return Future { resolver in
self.getDocuments(source: source) { (documents, error) in
if let error = error {
resolver.set(error)
} else {
resolver.set(documents!)
}
}
}
}

public func observe(includeMetadataChanges: Bool = false) -> Observable<QuerySnapshot> {
return Observable { resolver in
let listener = addSnapshotListener(includeMetadataChanges: includeMetadataChanges) { (documents, error) in
if let error = error {
resolver.set(error)
} else {
resolver.set(documents!)
}
}
resolver.onDeinit {
listener.remove()
}
}
}
}

extension DocumentReference {
public func get(source: FirestoreSource = .default) -> Future<DocumentSnapshot> {
return Future { resolver in
getDocument(source: source) { (document, error) in
if let error = error {
resolver.set(error)
} else {
resolver.set(document!)
}
}
}
}

public func observe(includeMetadataChanges: Bool = false) -> Observable<DocumentSnapshot> {
return Observable { resolver in
let listener = addSnapshotListener(includeMetadataChanges: includeMetadataChanges) { (document, error) in
if let error = error {
resolver.set(error)
} else {
resolver.set(document!)
}
}
resolver.onDeinit {
listener.remove()
}
}
}

public func put(data: [String : Any], merge : Bool = true) -> Future<Void> {
return Future { resolver in
setData(data, merge: merge) { error in
if let error = error {
resolver.set(error)
} else {
resolver.set()
}
}
}
}

public func delete() -> Future<Void> {
return Future { resolver in
delete { error in
if let error = error {
resolver.set(error)
} else {
resolver.set()
}
}
}
}
}


extension CollectionReference {
public func put(data: [String : Any]) -> Future<Void> {
return Future { resolver in
addDocument(data: data) { error in
if let error = error {
resolver.set(error)
} else {
resolver.set()
}
}
}
}
}

0 comments on commit 5821ffa

Please sign in to comment.