-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package re-structure #280
Package re-structure #280
Conversation
tonikocjan
commented
May 8, 2023
•
edited
Loading
edited
- Re-structured package:
- PovioKitCore
- Extensions/
- PKNetworking
- ANC/
- PKPromiseKit
- Promise/
- PKSwiftUI
- Extensions/
- ActionButton/
- ProfileImageView/
- PKUIKit
- DynamicCollectionCell/
- GradientView/
- PaddingLabel
- TextField
- PKUtilities
- a lot of stuff
- PovioKitCore
- Support for MacOS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the new structure. The core is now small and lean 💪
do { | ||
return try decoder.decode(type, from: self) | ||
} catch let decodingError as DecodingError { | ||
switch decodingError { | ||
case .typeMismatch(_, let context), | ||
.valueNotFound(_, let context), | ||
.keyNotFound(_, let context), | ||
.dataCorrupted(let context): | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": context.debugDescription]) | ||
@unknown default: | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": "Unknown decoding error."]) | ||
} | ||
throw decodingError | ||
} catch { | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": error.localizedDescription]) | ||
throw error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Logger is part of the
Utilities
package, do not wantCore
to depend on the subpackage. - Logging should be done on the client side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't agree with both points.
- True, but since the Logger is really the core of the whole package, I would leave it in the
Core
package. - That should be part of the library. Client doesn't and shouldn't know about the implementation details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be part of the library. Client doesn't and shouldn't know about the implementation details.
I disagree. A simple extension function such as this one should be completely pure, i.e. it should not modify the global state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still tend to disagree. Extension is here for a reason, to "extend" the core functionality. By slashing pretty much all the code, the code left is meaningless, no gain for the developer. We have two options:
- revert the change
- remove the method completely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function itself is fine, it extends core functionality to use your lingo. But I would not force upon the user as to how they want to handle (and log) the errors.
If it comes to this I will just remove the method.
func encode(with encoder: JSONEncoder) throws -> [String: Any] { | ||
do { | ||
let data = try encoder.encode(self) | ||
guard let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { | ||
throw JSONError.serialization | ||
} | ||
return jsonObject | ||
} catch let encodingError as EncodingError { | ||
switch encodingError { | ||
case .invalidValue(_, let context): | ||
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": context.debugDescription]) | ||
@unknown default: | ||
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": "Unknown encoding error."]) | ||
} | ||
throw encodingError | ||
} catch { | ||
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": error.self]) | ||
throw error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Either revert the change or remove the method completely.
do { | ||
return try decoder.decode(type, from: self) | ||
} catch let decodingError as DecodingError { | ||
switch decodingError { | ||
case .typeMismatch(_, let context), | ||
.valueNotFound(_, let context), | ||
.keyNotFound(_, let context), | ||
.dataCorrupted(let context): | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": context.debugDescription]) | ||
@unknown default: | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": "Unknown decoding error."]) | ||
} | ||
throw decodingError | ||
} catch { | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": error.localizedDescription]) | ||
throw error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't agree with both points.
- True, but since the Logger is really the core of the whole package, I would leave it in the
Core
package. - That should be part of the library. Client doesn't and shouldn't know about the implementation details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. Although I have a few concerns:
- PR should re-structure the package, but is also doing other things
- PR is adding support for macos
- PR is changing existing code
We are doing three things in one PR which should be split into three separate PRs. I'm ok with first two points above to be done here, but let's scrap the third out into a separate PR.
do { | ||
return try decoder.decode(type, from: self) | ||
} catch let decodingError as DecodingError { | ||
switch decodingError { | ||
case .typeMismatch(_, let context), | ||
.valueNotFound(_, let context), | ||
.keyNotFound(_, let context), | ||
.dataCorrupted(let context): | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": context.debugDescription]) | ||
@unknown default: | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": "Unknown decoding error."]) | ||
} | ||
throw decodingError | ||
} catch { | ||
Logger.debug("Decoding (failure): \(type.self)", params: ["error": error.localizedDescription]) | ||
throw error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still tend to disagree. Extension is here for a reason, to "extend" the core functionality. By slashing pretty much all the code, the code left is meaningless, no gain for the developer. We have two options:
- revert the change
- remove the method completely
func encode(with encoder: JSONEncoder) throws -> [String: Any] { | ||
do { | ||
let data = try encoder.encode(self) | ||
guard let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { | ||
throw JSONError.serialization | ||
} | ||
return jsonObject | ||
} catch let encodingError as EncodingError { | ||
switch encodingError { | ||
case .invalidValue(_, let context): | ||
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": context.debugDescription]) | ||
@unknown default: | ||
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": "Unknown encoding error."]) | ||
} | ||
throw encodingError | ||
} catch { | ||
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": error.self]) | ||
throw error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Either revert the change or remove the method completely.
Great work @tonikocjan. We need some additional changes:
|
Apple also has a separate swift package for Async data structures and algorithms. I think separating makes sense as a user might only need some async algorithm that we provide.
The other async code is already nicely contained in the Networking and Promise sub-packages. Any other code that strongly utilizes Swift concurrency, should be moved inside the Async package. |
Revert promise changes +1
Great. Let's proceed 👌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌