Skip to content
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

Improve DeepLinking by accessing the stored value of @Published properties directly #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pauljohanneskraft
Copy link
Collaborator

No description provided.


fileprivate func values<Value>(_ compactMap: (Any) -> Value?) -> [Value] {
children.compactMap { compactMap($0.value) }
+ (superclassMirror?.values(compactMap) ?? [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the compactMap closure as it's not a compact map, it's the function that is applied by compact map (but not only!).

Suggestion: mappingFunction or transform.

(I know this code was just moved, but I only noticed it now.)

Also, this is a good example where more code is easier to read:

func values<Value>(_ mappingFunction: (Any) -> Value?) -> [Value] {
    let values = children.compactMap { mappingFunction($0.value) }

    if let superClassValues = superclassMirror?.values(mappingFunction) {
        return values + superClassValues
    } else {
        return values
    }
}

This makes it much more visible when recursion occurs and which is the recursion anchor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also not sure about the function name values but I see where it comes from and I don't have a better idea right now.)


public var content: Any {
guard let value = Mirror(reflecting: self).descendant("storage", "value") else {
assertionFailure("We could not extract a wrappedValue from a Published property wrapper.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who's "we"? 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants