diff --git a/src/lib/FusionTablesLayer.js b/src/lib/FusionTablesLayer.js deleted file mode 100644 index 4f13040d..00000000 --- a/src/lib/FusionTablesLayer.js +++ /dev/null @@ -1,98 +0,0 @@ -/* global google */ -import _ from "lodash"; - -import PropTypes from "prop-types"; - -import createReactClass from "create-react-class"; - -import { - MAP, - FUSION_TABLES_LAYER, -} from "./constants"; - -import { - addDefaultPrefixToPropTypes, - collectUncontrolledAndControlledProps, - default as enhanceElement, -} from "./enhanceElement"; - -const controlledPropTypes = { - // NOTICE!!!!!! - // - // Only expose those with getters & setters in the table as controlled props. - // - // [].map.call($0.querySelectorAll("tr>td>code", function(it){ return it.textContent; }) - // .filter(function(it){ return it.match(/^set/) && !it.match(/^setMap/); }) - // - // https://developers.google.com/maps/documentation/javascript/3.exp/reference#FusionTablesLayer - options: PropTypes.object, -} - -const defaultUncontrolledPropTypes = addDefaultPrefixToPropTypes(controlledPropTypes); - -const eventMap = { - // https://developers.google.com/maps/documentation/javascript/3.exp/reference#FusionTablesLayer - // [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }) - onClick: `click`, -}; - -const publicMethodMap = { - // Public APIs - // - // https://developers.google.com/maps/documentation/javascript/3.exp/reference#FusionTablesLayer - // - // [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }) - // .filter(function(it){ return it.match(/^get/) && !it.match(/Map$/); }) - // END - Public APIs -} - -const controlledPropUpdaterMap = { - options(fusionTablesLayer, options) { fusionTablesLayer.setOptions(options); }, -}; - -function getInstanceFromComponent(component) { - return component.state[FUSION_TABLES_LAYER]; -} - -export default _.flowRight( - createReactClass, - enhanceElement(getInstanceFromComponent, publicMethodMap, eventMap, controlledPropUpdaterMap), -)({ - displayName: `FusionTablesLayer`, - - propTypes: { - ...controlledPropTypes, - ...defaultUncontrolledPropTypes, - }, - - contextTypes: { - [MAP]: PropTypes.object, - }, - - getInitialState() { - const fusionTablesLayer = new google.maps.FusionTablesLayer({ - map: this.context[MAP], - query: this.props.options.query, - ...collectUncontrolledAndControlledProps( - defaultUncontrolledPropTypes, - controlledPropTypes, - this.props - ), - }); - - return { - [FUSION_TABLES_LAYER]: fusionTablesLayer, - }; - }, - - componentWillUnmount() { - const fusionTablesLayer = getInstanceFromComponent(this); - if (fusionTablesLayer) { - fusionTablesLayer.setMap(null); - } - }, - - render() { - return false; - }, -}); \ No newline at end of file diff --git a/src/macros/FusionTablesLayer.jsx b/src/macros/FusionTablesLayer.jsx new file mode 100644 index 00000000..e173bf8c --- /dev/null +++ b/src/macros/FusionTablesLayer.jsx @@ -0,0 +1,81 @@ +/* global google */ +import React from "react" +import PropTypes from "prop-types" + +import { + construct, + componentDidMount, + componentDidUpdate, + componentWillUnmount, +} from "../utils/MapChildHelper" + +import { MAP, FUSION_TABLES_LAYER } from "../constants" + +export const __jscodeshiftPlaceholder__ = `{ + "eventMapOverrides": { + }, + "getInstanceFromComponent": "this.state[FUSION_TABLES_LAYER]" +}` + +/** + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#FusionTablesLayer + */ +export class FusionTablesLayer extends React.PureComponent { + static propTypes = { + __jscodeshiftPlaceholder__: null, + } + + static contextTypes = { + [MAP]: PropTypes.object, + } + + /* + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#FusionTablesLayer + */ + constructor(props, context) { + super(props, context) + const fusionTablesLayer = new google.maps.FusionTablesLayer() + construct( + FusionTablesLayer.propTypes, + updaterMap, + this.props, + fusionTablesLayer + ) + fusionTablesLayer.setMap(this.context[MAP]) + this.state = { + [FUSION_TABLES_LAYER]: fusionTablesLayer, + } + } + + componentDidMount() { + componentDidMount(this, this.state[FUSION_TABLES_LAYER], eventMap) + } + + componentDidUpdate(prevProps) { + componentDidUpdate( + this, + this.state[FUSION_TABLES_LAYER], + eventMap, + updaterMap, + prevProps + ) + } + + componentWillUnmount() { + componentWillUnmount(this) + const fusionTablesLayer = this.state[FUSION_TABLES_LAYER] + if (fusionTablesLayer) { + fusionTablesLayer.setMap(null) + } + } + + render() { + return false + } +} + +export default FusionTablesLayer + +const eventMap = {} + +const updaterMap = {}