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

[ios, macos] rename style spec properties #7128

Merged
merged 1 commit into from
Nov 30, 2016

Conversation

frederoni
Copy link
Contributor

Fixes #6098

Started with the most obvious properties to avoid confusion and sloppiness.

  • icon-image => icon-image-name
  • raster-brightness-min => raster-brightness-minimum
  • raster-brightness-max => raster-brightness-maximum

line-dasharray is another one that doesn't feel particularly idiomatic but I'm ok with it and the remaining circlePitchScale & rasterHueRotate that @1ec5 pointed out #6098 (comment).

@1ec5 @boundsj 👀

@frederoni frederoni added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS release blocker Blocks the next final release runtime styling labels Nov 21, 2016
@frederoni frederoni added this to the ios-v3.4.0 milestone Nov 21, 2016
@frederoni frederoni self-assigned this Nov 21, 2016
@mention-bot
Copy link

@frederoni, thanks for your PR! By analyzing the history of the files in this pull request, we identified @1ec5, @fabian-guerra and @incanus to be potential reviewers.

@frederoni frederoni added the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Nov 21, 2016
@frederoni frederoni removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Nov 21, 2016
"icon-image": "icon-image-name"
},
"paint_raster": {
"raster-brightness-min": "raster-brightness-minimum",
Copy link
Contributor

Choose a reason for hiding this comment

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

minimumRasterBrightness reads better. We might as well make that change as long as we're renaming this property.

_.forOwn(overrides, function (value, key) {
const keyPath = stack + '.';
if (_.isObject(value)) {
renameProperties(obj, overrides[key], stack.length ? keyPath + key : key);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this function need to be recursive? Seems like we could assume a two-level-deep override object and use subscript notation instead of _.set and _.unset.

@frederoni frederoni force-pushed the fred-rename-prop-6098 branch 3 times, most recently from bd082bd to 951c716 Compare November 24, 2016 17:24
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.

Almost there. By addressing the sorting issue, this diff will get a lot smaller.

_.forOwn(cocoaConventions, function (properties, kind) {
_.forOwn(properties, function (newName, oldName) {
spec[kind][newName] = spec[kind][oldName];
spec[kind][newName]["_original"] = oldName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: normally, in JavaScript, you’d say .original instead of ["_original"].

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack, sorry, I meant ._original. You were right about trying to avoid a theoretical conflict with a property named original.

@@ -212,6 +221,10 @@ global.propertyDefault = function (property, layerType) {
return 'an `MGLStyleValue` object containing ' + describeValue(property.default, property, layerType);
};

global.originalPropertyName = function (property) {
return property._original ? property._original : property.name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this can be simplified as property._original || property.name.

@@ -21,9 +21,9 @@ namespace mbgl {
<% if (layoutProperties.length) { -%>
<% for (const property of layoutProperties) { -%>
Copy link
Contributor

Choose a reason for hiding this comment

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

We’ve been relying on an implementation detail of v8 whereby an object’s properties are enumerated in the order that they’re added to the object. Unfortunately, all the renamed properties appear last in the generated source code, which is a little jarring.

To fix this issue, we’d need to sort layoutProperties’ keys before enumerating the object:

let sortedLayoutProperties = _.pick(layoutProperties, _.keysIn(layoutProperties).sort());

There are probably more efficient ways of doing this, but this way involves less typing. 😉

Copy link
Contributor Author

@frederoni frederoni Nov 29, 2016

Choose a reason for hiding this comment

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

After the style spec has been processed, the key is removed and inserted into the object as name so I sorted with _.sortBy(layoutProperties, ['name']. Unfortunately, it wasn't very well sorted before so the diff increased quite a bit. Separate commits to make it easier to review.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mistakenly thought the properties were alphabetically sorted to begin with, but you’re right that the properties are far from sorted in the style specification’s JSON objects. The official documentation is generated using v8, just like our generated runtime styling files, so for example icon-rotate comes before icon-padding. @lucaswoj doesn’t know of any reason we need to keep the properties in that order, so alphabetizing the properties makes sense because it’ll make it easier to find them in our jazzy documentation.

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 release blocker Blocks the next final release runtime styling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants