-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FusionTablesLayer): add component
* Original commit: fd01d44 * Original author: @RishabhJain96 * Closes #370
- Loading branch information
1 parent
83b1e1b
commit 1d8e478
Showing
4 changed files
with
106 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* global google */ | ||
import _ from 'lodash'; | ||
|
||
import { | ||
default as React, | ||
PropTypes, | ||
} from 'react'; | ||
|
||
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( | ||
React.createClass, | ||
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], | ||
...collectUncontrolledAndControlledProps( | ||
defaultUncontrolledPropTypes, | ||
controlledPropTypes, | ||
this.props | ||
), | ||
}); | ||
|
||
return { | ||
[FUSION_TABLES_LAYER]: fusionTablesLayer, | ||
}; | ||
}, | ||
|
||
componentWillUnmount() { | ||
const fusionTablesLayer = getInstanceFromComponent(this); | ||
if (fusionTablesLayer) { | ||
fusionTablesLayer.setMap(null); | ||
} | ||
}, | ||
|
||
render() { | ||
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
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