Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
177 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
examples/experimental/json-layer/json-layer/json-layer.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
examples/playground/src/deck-json-converter/deck-json-configuration.js
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
// @deck.gl/json: top-level exports | ||
|
||
// Generic JSON converter, usable by other wrapper modules | ||
export {default as _JSONConverter} from './lib/json-converter'; | ||
export {default as _JSONConfiguration} from './lib/json-configuration'; | ||
export {default as JSONConverter} from './lib/json-converter'; | ||
export {default as JSONConfiguration} from './lib/json-configuration'; | ||
|
||
// Helpers | ||
export {default as _convertFunctions} from './lib/helpers/convert-functions'; | ||
export {default as _parseExpressionString} from './lib/helpers/parse-expression-string'; | ||
export {shallowEqualObjects as _shallowEqualObjects} from './utils/shallow-equal-objects'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import parseExpressionString from './parse-expression-string'; | ||
import {getPropTypes, isFunctionProp} from './deck-prop-types'; | ||
|
||
// Try to determine if any props are function valued | ||
// and if so convert their string values to functions | ||
export default function convertFunctions(Class, props, configuration) { | ||
const propTypes = getPropTypes(Class); | ||
if (!propTypes) { | ||
return props; | ||
} | ||
|
||
// Use deck.gl prop types if available. | ||
return convertFunctionsUsingPropTypes(Class, props, propTypes, configuration); | ||
} | ||
|
||
function convertFunctionsUsingPropTypes(Class, props, propTypes, configuration) { | ||
const replacedProps = {}; | ||
for (const propName in props) { | ||
let propValue = props[propName]; | ||
|
||
// Parse string valued expressions | ||
const isFunction = isFunctionProp(propTypes, propName); | ||
|
||
// Parse string as "expression", return equivalent JavaScript function | ||
if (isFunction && typeof propValue === 'string') { | ||
const isAccessor = true; | ||
propValue = parseExpressionString(propValue, configuration, isAccessor); | ||
} | ||
|
||
// Invalid functions return null, show default value instead. | ||
if (propValue) { | ||
replacedProps[propName] = propValue; | ||
} | ||
} | ||
|
||
return replacedProps; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// NOTE - This is sniffing for deck.gl prop types | ||
// TODO - We may want to do something similar for React `prop-types` | ||
// TODO - We need something similar for non-deck, non-React classes | ||
// TODO - The deck prop types system could potentially be exported as a general prop types package.... | ||
|
||
export function getPropTypes(Class) { | ||
let propTypes = Class && Class._propTypes && Class._propTypes; | ||
// HACK: Trigger generation of propTypes | ||
if (!propTypes && Class.defaultProps) { | ||
new Class({}); // eslint-disable-line no-new | ||
propTypes = Class && Class._propTypes && Class._propTypes; | ||
} | ||
return propTypes; | ||
} | ||
|
||
export function isFunctionProp(propTypes, propName) { | ||
const propType = propTypes && propTypes[propName]; | ||
if (!propType) { | ||
// TODO - simple heuristic if prop types are not avaialable | ||
return propName.startsWith('get'); | ||
} | ||
|
||
const type = typeof propType === 'object' && propType.type; | ||
switch (type) { | ||
case 'accessor': | ||
case 'function': | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.