Skip to content

Commit

Permalink
Minor improvements to style mapper warning messages
Browse files Browse the repository at this point in the history
- Warning for null data() mapper
- Warning for function() mapper with null return value
- Warning for function() mapper with invalid return value w.r.t. property type

Ref @2209
  • Loading branch information
maxkfranz committed Oct 30, 2018
1 parent 96f9862 commit 3cd84da
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/style/apply.js
Expand Up @@ -435,7 +435,7 @@ styfn.applyParsedProperty = function( ele, parsedProp ){
}

let printMappingErr = function(){
util.warn( 'Do not assign mappings to elements without corresponding data (e.g. ele `' + ele.id() + '` for property `' + prop.name + '` with data field `' + prop.field + '`); try a `[' + prop.field + ']` selector to limit scope to elements with `' + prop.field + '` defined' );
util.warn( 'Do not assign mappings to elements without corresponding data (i.e. ele `' + ele.id() + '` has no mapping for property `' + prop.name + '` with data field `' + prop.field + '`); try a `[' + prop.field + ']` selector to limit scope to elements with `' + prop.field + '` defined' );
};

// put the property in the style objects
Expand All @@ -452,7 +452,7 @@ styfn.applyParsedProperty = function( ele, parsedProp ){

if( fieldVal == null ){
printMappingErr();
return;
return false;
}

let percent;
Expand Down Expand Up @@ -530,7 +530,9 @@ styfn.applyParsedProperty = function( ele, parsedProp ){
fieldVal = fieldVal[ field ];
}

flatProp = this.parse( prop.name, fieldVal, prop.bypass, flatPropMapping );
if( fieldVal != null ){
flatProp = this.parse( prop.name, fieldVal, prop.bypass, flatPropMapping );
}

if( !flatProp ){ // if we can't flatten the property, then don't apply and fall back on the existing style
printMappingErr();
Expand All @@ -547,7 +549,18 @@ styfn.applyParsedProperty = function( ele, parsedProp ){
let fn = prop.value;
let fnRetVal = fn( ele );

if( fnRetVal == null ){
util.warn('Custom function mappers may not return null (i.e. `' + prop.name + '` for ele `' + ele.id() + '` is null)');
return false;
}

flatProp = this.parse( prop.name, fnRetVal, prop.bypass, flatPropMapping );

if( !flatProp ){
util.warn('Custom function mappers may not return invalid values for the property type (i.e. `' + prop.name + '` for ele `' + ele.id() + '` is invalid)');
return false;
}

flatProp.mapping = prop; // keep a reference to the mapping
prop = flatProp; // the flattened (mapped) property is the one we want

Expand Down

0 comments on commit 3cd84da

Please sign in to comment.