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

[ios, macos] Add lookup and feature operators. - #11528

Merged
fabian-guerra merged 6 commits into
release-bobafrom
fabian-feature-lookup-11006
Mar 28, 2018
Merged

fabian-guerra merged 6 commits into
release-bobafrom
fabian-feature-lookup-11006

Conversation

@fabian-guerra

@fabian-guerra fabian-guerra commented Mar 26, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #11006

Add operators

  • geometry-type.
  • id.
  • properties.
  • at.
  • has.
  • Tests.

@fabian-guerra fabian-guerra added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS beta blocker Blocks the next beta release labels Mar 26, 2018
@fabian-guerra fabian-guerra added this to the ios-v4.0.0 milestone Mar 26, 2018
@fabian-guerra fabian-guerra self-assigned this Mar 26, 2018
@fabian-guerra
fabian-guerra force-pushed the fabian-feature-lookup-11006 branch from 3167c94 to 9b08744 Compare March 26, 2018 19:28
@fabian-guerra
fabian-guerra requested a review from 1ec5 March 26, 2018 20:41
@fabian-guerra fabian-guerra changed the title [ios, macos] Add Expressions 'at' operator. [ios, macos] Add lookup and feature operators. Mar 26, 2018
@1ec5

1ec5 commented Mar 27, 2018

Copy link
Copy Markdown
Contributor

By the way, I’ve been using this header as a guide to which built-in syntaxes (like subscripting) correspond to which built-in expression functions (objectFrom:withIndex:).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[NSExpression expressionWithFormat:@"{1, 2, 3}[index]"] has a function of objectFrom:withIndex: and an arguments consisting of the expression index.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Conventional custom functions should be prefixed with mgl_ to avoid conflicting with functions that Apple may add to NSExpression in the future.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This SDK is using the $variable syntax both for these special built-in values that vary based on the execution context and also for user-defined variables. The assumption with zoomLevel and the like is that developers will be less likely to need a variable by that exact name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency with Cocoa and this SDK, either spell this function featureID or, better yet, featureIdentifier.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The has operator has two forms. You can think of the ["has", "something"] form as shorthand for ["has", "something", ["properties"]]. This PR only implements one of the two forms.

["has", "something"] should translate to FUNCTION(self, 'mgl_has:', 'something'), and ["has", "something", object] should translate to FUNCTION(object, 'mgl_has:', 'something').

@fabian-guerra
fabian-guerra force-pushed the fabian-feature-lookup-11006 branch from 441a524 to ae3df5c Compare March 28, 2018 18:40
NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects);
NSExpression *operand = argumentObjects.count > 1 ? subexpressions[1] : [NSExpression expressionWithFormat:@"self"];
NSExpression *property = subexpressions.firstObject;
return [NSExpression expressionWithFormat:@"FUNCTION(%@, 'mgl_has:', %@)", operand, property];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By the way, a preexisting way to write this in an expression would be FUNCTION(%@, 'valueForKey:', %@) != nil. That seems a bit more natural, although I guess mgl_has: will be slightly more ergonomic once we implement an aftermarket function for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For this case mgl_has: seems like the most ergonomic option as its closer to our spec.

if ([self.variable isEqualToString:@"mgl_geometryType"]) {
return @[@"geometry-type"];
}
if ([self.variable isEqualToString:@"featureIdentifier"]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mgl_geometryType is prefixed with the class prefix, but featureIdentifier and featureProperties are not.

return self.arguments.firstObject.mgl_jsonExpressionObject;
} else if ([function isEqualToString:@"mgl_has:"]) {
NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"has", self.arguments[0].mgl_jsonExpressionObject, nil];
if (self.operand.expressionType == NSConstantValueExpressionType) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FUNCTION($featureProperties, 'mgl_has:', 'property') should be translated as ["has", ["properties"], "property"], so we need to check here that the operand isn’t an NSEvaluatedObjectExpressionType (i.e., SELF).

@fabian-guerra
fabian-guerra merged commit 2aaa038 into release-boba Mar 28, 2018
@fabian-guerra
fabian-guerra deleted the fabian-feature-lookup-11006 branch March 28, 2018 22:09
@1ec5 1ec5 mentioned this pull request Mar 29, 2018
13 of 16 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beta blocker Blocks the next beta release 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.

2 participants