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

[ios, macos] Warn if MGLShapeSource is initialized with MGLShapeCollection #12625

Merged
merged 1 commit into from
Aug 20, 2018

Conversation

captainbarbosa
Copy link
Contributor

Closes #11287 by throwing a single warning if any MGLShapeCollection contains a shape conforming to MGLFeature protocol, as attributes are not copied over into MGLShapeCollections.

@captainbarbosa captainbarbosa added the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Aug 14, 2018
@captainbarbosa captainbarbosa self-assigned this Aug 14, 2018
@captainbarbosa captainbarbosa changed the title [ios] Warn if shape collection is initialized with MGLFeature [ios, macos] Warn if shape collection is initialized with MGLFeature Aug 14, 2018
@captainbarbosa captainbarbosa added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS labels Aug 14, 2018
@captainbarbosa
Copy link
Contributor Author

I've gotten this warning to show up when initializing a new MGLShapeCollection (yay), but for some reason this warning is also being thrown when initializing a MGLShapeCollectionFeature (🤔), which shouldn't happen.

@captainbarbosa captainbarbosa requested a review from 1ec5 August 14, 2018 23:44
@"This will be logged only once.");
});
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

This code breaks out of the loop, unconditionally, after considering the first shape in the array. I think the intention is to consider each of the shapes, breaking if one of them is a feature.

@@ -13,6 +14,18 @@ + (instancetype)shapeCollectionWithShapes:(NSArray<MGLShape *> *)shapes {
- (instancetype)initWithShapes:(NSArray<MGLShape *> *)shapes {
if (self = [super init]) {
_shapes = shapes.copy;

for (MGLShape* shape in shapes ){
if ([shape conformsToProtocol:@protocol(MGLFeature)]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting the feature check here does address a common mistake, but #11287 was specifically about warning when creating an MGLShapeSource with an MGLShapeCollection or setting MGLShapeSource.shape to an MGLShapeCollection. That would occur later than this code; the only difference is that there may theoretically be a legitimate reason to stuff MGLFeatures in an MGLShapeCollection, but there’s no reason to stick an MGLShapeCollection inside an MGLShapeSource or MGLComputedShapeSource. On the other hand, it’s always nicer to warn as soon as we see a potential problem unfolding. Your call as to the proper tradeoff.

@1ec5
Copy link
Contributor

1ec5 commented Aug 15, 2018

I've gotten this warning to show up when initializing a new MGLShapeCollection (yay), but for some reason this warning is also being thrown when initializing a MGLShapeCollectionFeature (🤔), which shouldn't happen.

MGLShapeCollectionFeature inherits from MGLShapeCollection.

+ (instancetype)shapeCollectionWithShapes:(NSArray<MGLShape<MGLFeature> *> *)shapes {
return [super shapeCollectionWithShapes:shapes];
}

Per #12625 (comment), we could instead have MGLShapeSource and MGLComputedShapeSource check whether they’re getting MGLShapeCollections. That would be an O(1) operation rather than an O(n) operation, and we can be sure the check would only snag improper use of MGLShapeCollection where MGLShapeCollectionFeature was intended.

@captainbarbosa captainbarbosa changed the title [ios, macos] Warn if shape collection is initialized with MGLFeature [ios, macos] Warn if MGLShapeSource is initialized with MGLShapeCollection Aug 17, 2018
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.

This looks good. Your call as to whether the change warrants a changelog entry.

@captainbarbosa captainbarbosa force-pushed the nb-warn-attribute-loss-11287 branch from 270f9da to a7f7b09 Compare August 20, 2018 21:03
Move warning from ShapeCollection to ShapeSource

Try checking MGLComputedShapeSources

Include MGLShapeCollection header

Add changelog entry
@captainbarbosa captainbarbosa force-pushed the nb-warn-attribute-loss-11287 branch from 3ca52d4 to 8ad51b0 Compare August 20, 2018 22:17
@captainbarbosa captainbarbosa removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Aug 20, 2018
@captainbarbosa captainbarbosa merged commit 5005965 into master Aug 20, 2018
@captainbarbosa captainbarbosa deleted the nb-warn-attribute-loss-11287 branch August 20, 2018 22:45
@JacobJT
Copy link

JacobJT commented Aug 21, 2018

I haven't tested and may be wrong, but since these all have a scoped dispatch_once_t, it seems to me one could trigger this three separate times if they vary their implementations. Not that it's a problem, I'd rather get it a few times than none, but thought I'd point it out.

@julianrex
Copy link
Contributor

@JacobJT thanks for the comment. I've created a ticket.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants