-
Notifications
You must be signed in to change notification settings - Fork 7
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
Localize all or nothing #129
Conversation
This reverts commit 05dc619.
cda60d6
to
06255f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't gotten too far yet, but wanted to send what I have before a meeting
// no-op on any property called "worldview" if worldviews have been | ||
// created dynamically from _mbx_wordlview | ||
if (!worldview.empty() && property.first == "worldview") | ||
if (property.first == worldview_key) // safeguard – should always evaluate to false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should this always be false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in the current implementation, when we encounter {worldview_property}
or {worldview_prefix}{worldview_property}
while looping through the properties, we only store the worldviews to create in the worldviews_to_create
variable but not add them to the final_properties
vector. After we're done looping through the properties, we decide how many clones of the feature to build (for now we are limiting to 1) and what each clone should have as its {worldview_property}
.
This safeguard is to prevent future code change that might accidentally/unintentionally add worldview to final_properties
, and also to make clear for humans that worldview_key
of the property always come from worldview_val
.
while (auto property = feature.next_property()) | ||
{ | ||
// if already know we'll be skipping this feature, don't need to comb through its properties | ||
if (skip_feature) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this added to the while? while (property = next_property && !skip_feature)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately no, that turns property
into bool type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear I meant something like
while (!skip_feature && auto feature = layer.next_feature())
rather than have the skip_feature check on L739.
It's not a very important detail but would be a little more readable IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The while loop while (auto feature = layer.next_feature())
is for looping through the features one by one; we don't know whether we can skip a feature or not before we look at its properties, so skip_feature
is always false when we evaluate this while condition. The skip_feature
flag changes to true when we encounter a property that suggests we can discard this feature, and the flag resets to false when we are done with one feature and moves on to the next feature. I'll add a comment to clarify this.
while (!skip_feature && auto property = feature.next_property())
results in this error:
../src/vtcomposite.cpp:736:45: error: expected expression
while (!skip_feature && auto property = feature.next_property())
^
../src/vtcomposite.cpp:744:52: error: use of undeclared identifier 'property'
std::string property_key = property.key().to_string();
^
and while (auto property = feature.next_property() && !skip_feature)
results in this error:
../src/vtcomposite.cpp:744:60: error: member reference base type 'bool' is not a structure or union
std::string property_key = property.key().to_string();
~~~~~~~~^~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more details to the comments re: skip_feature
in 759e709.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! My only real request is to move to v2. Other things are less critical code style and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lily-chai initial read-through looks really great, nice to see some explicit variable names set to help dictate the flow of the feature/property parsing.
I left some questions just to ask for clarifications. But after reading through all of your tests I'm feeling quite confident in the changes here!
src/vtcomposite.cpp
Outdated
language_key = baton_data_->language_property + "_" + baton_data_->language; | ||
// {language_prefix}{language_property}_{language} -> drop | ||
language_key_prefixed = baton_data_->language_prefix + language_key; | ||
keep_every_worldview = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why reset to true
if the default is already true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clarity – this way it's easier for the human brain to see the difference between the configuration localized tile (the if block) and the configuration for non-localized tile (the else block). If you're not against leaving this in, I'll add a comment to explain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment in 3711e05.
localize(params, (err, vtBuffer) => { | ||
assert.ifError(err); | ||
const tile = vtinfo(vtBuffer); | ||
assert.deepEqual(tile.layers, {}, 'has no feature'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to confirm, we're dropping this feature because we anticipate another feature with _mbx_worldview
to exist with the value assigned as US
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
'name_fr': 'Allemagne', // choosing first encountered property in (name_fr, _mbx_name_fr) | ||
name: 'Allemagne', // name_{language} takes precedence over _mbx_name_{language} | ||
name_local: 'Germany', | ||
_mbx_other: 'Alemania' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we drop arbitrary _mbx*
fields anymore?
Ask because I'd expect someone to add fields to their data expecting us to remove them as "internal-only" fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the params for language, worldview and class more consistent:
- Before: we can specify a prefix for language, but not for class and worldview. It isn't clear why.
- After: we can specify a prefix for language, worldview and class. The prefixes can be different.
But that makes dropping fields confusing: for example, do we drop fields that match any of the 3 prefixes? Why do we want to drop a field that is irrelevant to e.g. worldview only because it has the the same prefix as worldview?
If we want to drop arbitrary _mbx_*
fields, I suggest having just one prefix param and call it something like params.hidden_prefix
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to drop arbitrary mbx* fields, I suggest having just one prefix param and call it something like params.hidden_prefix.
Irrespective of dropping all fields or not - I like this idea just to simplify the interface. I don't guess someone would set a different prefix for each kind of localizable field, yea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to one hidden_prefix
and drops any property that starts with this prefix in 00b9398.
Co-authored-by: Sam Matthews <sam@mapbox.com>
Co-authored-by: John Klancer <john.klancer@mapbox.com>
a32bea9
to
df9b1f4
Compare
df9b1f4
to
f7236b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎈 thanks for taking on this slightly head spinning work!
This PR cleans up the function
localize
. This function now only returns eitherSee README.md for more detail.