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

Custom AttributeOptions #748

Merged
merged 7 commits into from
Oct 10, 2022
Merged

Custom AttributeOptions #748

merged 7 commits into from
Oct 10, 2022

Conversation

Udumft
Copy link
Contributor

@Udumft Udumft commented Sep 22, 2022

Added AttributeOptions.customOptions and manipulation methods to allow custom options to be processed.

This is an approach to allow customization while avoiding breaking changes. The safer option would be to refactor AttributeOptions into a struct.

@Udumft Udumft requested a review from a team September 22, 2022 15:55
@Udumft Udumft self-assigned this Sep 22, 2022
@1ec5 1ec5 linked an issue Sep 22, 2022 that may be closed by this pull request
@1ec5
Copy link
Contributor

1ec5 commented Sep 22, 2022

This is an approach to allow customization while avoiding breaking changes. The safer option would be to refactor AttributeOptions into a struct.

For reference, this is tracked in #718 as a future backwards-incompatible change.

Sources/MapboxDirections/AttributeOptions.swift Outdated Show resolved Hide resolved
@@ -122,3 +135,101 @@ extension AttributeOptions: Codable {
self = AttributeOptions(descriptions: descriptions)!
}
}

extension AttributeOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pretty extensive extension that makes #718 all the more desirable. That said, the SetAlgebra protocol that OptionSet conforms to requires several other methods that OptionSet is currently implementing, now incompletely. The fundamental methods seem to be ==, intersection(_:), and union(_:), with all the others being derived from them. This is a different set of methods than what this extension implements, so I’m not sure if there would be inconsistencies as a result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. What I wanted to discuss before fully committing to the impl. is if this approach is really worth the result. I am inclined to call it over-engineered and potentially confusing to use, but it gets the job done in a nonbreaking way.
So do we need to allow options customizing even in suboptimal way now or we are OK to wait till it is time for API breakage update?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess my question was whether a different subset of methods (==, intersection(_:), and union(_:)) could be overridden to ensure that all the SetAlgebra methods works, since we can’t restrict which of those methods a developer will use in their code. If not, I agree that having to reimplement all the SetAlgebra methods just for AttributeOptions would be overkill. But our current use of OptionSet for RoadClasses similarly blocks further support for the Directions API, such as #662, so if the solution is general enough to cover both types, I think the additional code would be worth the trouble.

@Udumft Udumft force-pushed the vk/NAVIOS-374-attribute-options branch from 7f8aef6 to e3d946a Compare October 5, 2022 13:35
@Udumft Udumft requested a review from 1ec5 October 5, 2022 13:48
@Udumft Udumft marked this pull request as ready for review October 5, 2022 13:50
@Udumft Udumft requested a review from a team October 5, 2022 13:50
/// [1: "value1"] != [1: "value2"]
/// [1: "value1"] != [:]
/// [:] == [:]
case allowEqual
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about the naming at this point...

Copy link
Contributor

Choose a reason for hiding this comment

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

Just equal is fine, with precedent in MPSNNComparisonType.comparisonType, NSSpecifierTest.TestComparisonOperation, and BNNS.RelationalOperator.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Some renames, but the tests look convincing. The design of mapping strings to integers is unfortunate, but I don’t know how better to accommodate the expectations built into OptionSet.

Sources/MapboxDirections/AttributeOptions.swift Outdated Show resolved Hide resolved
/// [1: "value1"] != [1: "value2"]
/// [1: "value1"] != [:]
/// [:] == [:]
case allowEqual
Copy link
Contributor

Choose a reason for hiding this comment

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

Just equal is fine, with precedent in MPSNNComparisonType.comparisonType, NSSpecifierTest.TestComparisonOperation, and BNNS.RelationalOperator.

Sources/MapboxDirections/CustomValueOptionSet.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/CustomValueOptionSet.swift Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@Udumft Udumft force-pushed the vk/NAVIOS-374-attribute-options branch from fcae58c to 8a54bd9 Compare October 10, 2022 16:18
@Udumft Udumft merged commit 4254a18 into main Oct 10, 2022
@Udumft Udumft deleted the vk/NAVIOS-374-attribute-options branch October 10, 2022 16:32
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