Skip to content

Commit

Permalink
@deck.gl/json: Fix bug dropping props with falsy values (#4185)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajduberstein authored and Pessimistress committed Jan 23, 2020
1 parent 9cc7d2a commit aa6c40f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
6 changes: 1 addition & 5 deletions modules/json/src/helpers/convert-functions.js
Expand Up @@ -26,11 +26,7 @@ export default function convertFunctions(props, configuration) {
propValue = trimFunctionIdentifier(propValue);
propValue = parseExpressionString(propValue, configuration);
}

// Invalid functions return null, show default value instead.
if (propValue) {
replacedProps[propName] = propValue;
}
replacedProps[propName] = propValue;
}

return replacedProps;
Expand Down
2 changes: 1 addition & 1 deletion modules/json/src/helpers/instantiate-class.js
@@ -1,6 +1,6 @@
import convertFunctions from './convert-functions';

// This attempts to instantate a class. Eiher as a class or as a react component
// This attempts to instantiate a class, either as a class or as a React component
export function instantiateClass(type, props, configuration) {
// Find the class
const Class = configuration.classes[type];
Expand Down
30 changes: 30 additions & 0 deletions test/modules/json/helpers/convert-functions.spec.js
Expand Up @@ -4,6 +4,7 @@ import convertFunctions from '@deck.gl/json/helpers/convert-functions';

const TEST_CASES = [
{expr: 'true', expected: true}, // boolean literal
{expr: 'false', expected: false},

// array expression
{expr: '([1,2,3])[0]', expected: 1},
Expand Down Expand Up @@ -102,3 +103,32 @@ test('convertFunctions#asFunctions', t => {
}
t.end();
});

test('convertFunctions#assureAllKeysPresent', t => {
const EXAMPLE_PROPS = {
data: 'shp.geojson',
stroked: true,
filled: false,
lineWidthMinPixels: 2,
getElevation: '@@=x * 10',
opacity: 0.9
};

const convertedProps = convertFunctions(EXAMPLE_PROPS, {});
for (const key in EXAMPLE_PROPS) {
if (key !== 'getElevation') {
t.ok(
EXAMPLE_PROPS[key] === convertedProps[key],
`convertFunctions converted prop ${key} input to expected value ${EXAMPLE_PROPS[key]}`
);
} else {
t.ok(
convertedProps.getElevation({x: 10}) === 100,
`convertFunctions converted function ${key} to expected value, ${convertedProps.getElevation(
10
)}`
);
}
}
t.end();
});

0 comments on commit aa6c40f

Please sign in to comment.