Skip to content

Commit

Permalink
Address code review feedback (not including tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 committed Feb 2, 2019
1 parent 7dd421e commit b98e874
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Firestore/Swift/Source/Codable/CodableErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

enum FirestoreDecodingError: Error {
internal enum FirestoreDecodingError: Error {

This comment has been minimized.

Copy link
@wilhuff

wilhuff Feb 2, 2019

Contributor

If we're going to be throwing these to end users I don't think they can be internal.

case decodingIsNotSupported
}

enum FirestoreEncodingError: Error {
internal enum FirestoreEncodingError: Error {
case encodingIsNotSupported
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
import FirebaseFirestore

func isCodablePassThroughType<T: Any>(_ value: T) -> Bool {
internal func isFirestorePassthroughType<T: Any>(_ value: T) -> Bool {
return
T.self == GeoPoint.self ||
T.self == DocumentReference.self ||
Expand Down
26 changes: 0 additions & 26 deletions Firestore/Swift/Source/Codable/EncodeOrDie.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ extension _FirestoreDecoder {
return (decimal as! T)
}
if let _ = value as? Codable {
if isCodablePassThroughType(value as! T) {
if isFirestorePassthroughType(value as! T) {
// All the native Firestore types that should not be encoded
return (value as! T)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
import Foundation
import FirebaseFirestore

internal func encodeOrDie<T: Encodable>(_ value: T) -> [String: Any] {
do {
return try Firestore.encode(value)
} catch let error {
fatalError("Unable to encode data with Firestore encoder: \(error)")
}
}

extension Firestore {
public static func encode<T: Encodable>(_ value: T) throws -> [String: Any] {
guard let topLevel = try _FirestoreEncoder().box_(value) else {
Expand Down Expand Up @@ -342,7 +350,7 @@ extension _FirestoreEncoder {
return box((value as! URL).absoluteString)
} else if T.self == Decimal.self || T.self == NSDecimalNumber.self {
return (value as! NSDecimalNumber)
} else if isCodablePassThroughType(value) {
} else if isFirestorePassthroughType(value) {
// These are all native _Firestore types that we don't need to Encode
return (value as! NSObject)
}
Expand Down

0 comments on commit b98e874

Please sign in to comment.