Skip to content

Commit

Permalink
feat(src): update composeOptions to accept controlledPropTypes for _2
Browse files Browse the repository at this point in the history
* Ref #130
* Ref #125
* Ref #121
* Ref #112
* Ref #107
* Ref #107
  • Loading branch information
tomchentw committed Oct 13, 2015
1 parent 777fd83 commit 03aee4d
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 95 deletions.
12 changes: 5 additions & 7 deletions src/addons/addonsCreators/InfoBoxCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {default as componentLifecycleDecorator} from "../../utils/componentLifec
import {default as GoogleMapHolder} from "../../creators/GoogleMapHolder";

export const infoBoxControlledPropTypes = {
// NOTICE!!!!!!
//
// Only expose those with getters & setters in the table as controlled props.
//
// http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
content: PropTypes.any,
options: PropTypes.object,
Expand Down Expand Up @@ -57,13 +61,7 @@ export default class InfoBoxCreator extends Component {
// a isomorphic server.
const GoogleMapsInfobox = require("google-maps-infobox");
// http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
const infoBox = new GoogleMapsInfobox(composeOptions(infoBoxProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference
"content",
"position",
"visible",
"zIndex",
]));
const infoBox = new GoogleMapsInfobox(composeOptions(infoBoxProps, infoBoxControlledPropTypes));

if (infoBoxProps.children) {
setContentForOptionalReactElement(infoBoxProps.children, infoBox);
Expand Down
14 changes: 6 additions & 8 deletions src/creators/CircleCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const circleControlledPropTypes = {
// 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#Circle
center: PropTypes.any,
draggable: PropTypes.bool,
Expand Down Expand Up @@ -53,14 +58,7 @@ export default class CircleCreator extends Component {
static _createCircle (circleProps) {
const {mapHolderRef} = circleProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Circle
const circle = new google.maps.Circle(composeOptions(circleProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#CircleOptions
"center",
"draggable",
"editable",
"radius",
"visible",
]));
const circle = new google.maps.Circle(composeOptions(circleProps, circleControlledPropTypes));

circle.setMap(mapHolderRef.getMap());

Expand Down
12 changes: 6 additions & 6 deletions src/creators/DirectionsRendererCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const directionsRendererControlledPropTypes = {
// 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#DirectionsRenderer
directions: PropTypes.any,
options: PropTypes.object,
Expand Down Expand Up @@ -50,12 +55,7 @@ export default class DirectionsRendererCreator extends Component {
static _createDirectionsRenderer (directionsRendererProps) {
const {mapHolderRef} = directionsRendererProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#DirectionsRenderer
const directionsRenderer = new google.maps.DirectionsRenderer(composeOptions(directionsRendererProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#DirectionsRendererOptions
"directions",
"panel",
"routeIndex",
]));
const directionsRenderer = new google.maps.DirectionsRenderer(composeOptions(directionsRendererProps, directionsRendererControlledPropTypes));

directionsRenderer.setMap(mapHolderRef.getMap());

Expand Down
10 changes: 6 additions & 4 deletions src/creators/DrawingManagerCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const drawingManagerControlledPropTypes = {
// 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#DrawingManager
drawingMode: PropTypes.any,
options: PropTypes.object,
Expand Down Expand Up @@ -45,10 +50,7 @@ export default class DrawingManagerCreator extends Component {
static _createDrawingManager (drawingManagerProps) {
const {mapHolderRef} = drawingManagerProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#DrawingManager
const drawingManager = new google.maps.drawing.DrawingManager(composeOptions(drawingManagerProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#DrawingManagerOptions
"drawingMode",
]));
const drawingManager = new google.maps.drawing.DrawingManager(composeOptions(drawingManagerProps, drawingManagerControlledPropTypes));

drawingManager.setMap(mapHolderRef.getMap());

Expand Down
15 changes: 6 additions & 9 deletions src/creators/GoogleMapHolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {default as composeOptions} from "../utils/composeOptions";
import {default as componentLifecycleDecorator} from "../utils/componentLifecycleDecorator";

export const mapControlledPropTypes = {
// 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#Map
center: PropTypes.object,
heading: PropTypes.number,
Expand Down Expand Up @@ -52,15 +57,7 @@ export default class GoogleMapHolder extends Component {

static _createMap (domEl, mapProps) {
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map
return new google.maps.Map(domEl, composeOptions(mapProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#MapOptions
"center",
"heading",
"mapTypeId",
"streetView",
"tilt",
"zoom",
]));
return new google.maps.Map(domEl, composeOptions(mapProps, mapControlledPropTypes));
}

getMap () {
Expand Down
12 changes: 6 additions & 6 deletions src/creators/InfoWindowCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const infoWindowControlledPropTypes = {
// 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#InfoWindow
content: PropTypes.any,
options: PropTypes.object,
Expand Down Expand Up @@ -52,12 +57,7 @@ export default class InfoWindowCreator extends Component {
static _createInfoWindow (infoWindowProps) {
const {mapHolderRef, anchorHolderRef} = infoWindowProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoWindow
const infoWindow = new google.maps.InfoWindow(composeOptions(infoWindowProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoWindowOptions
"content",
"position",
"zIndex",
]));
const infoWindow = new google.maps.InfoWindow(composeOptions(infoWindowProps, infoWindowControlledPropTypes));

if (infoWindowProps.children) {
setContentForOptionalReactElement(infoWindowProps.children, infoWindow);
Expand Down
23 changes: 6 additions & 17 deletions src/creators/MarkerCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const markerControlledPropTypes = {
// 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#Marker
animation: PropTypes.any,
attribution: PropTypes.any,
Expand Down Expand Up @@ -72,23 +77,7 @@ export default class MarkerCreator extends Component {
static _createMarker (markerProps) {
const {mapHolderRef} = markerProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Marker
const marker = new google.maps.Marker(composeOptions(markerProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#MarkerOptions
"animation",
"attribution",
"clickable",
"cursor",
"draggable",
"icon",
"label",
"opacity",
"place",
"position",
"shape",
"title",
"visible",
"zIndex",
]));
const marker = new google.maps.Marker(composeOptions(markerProps, markerControlledPropTypes));

marker.setMap(mapHolderRef.getMap());

Expand Down
13 changes: 7 additions & 6 deletions src/creators/OverlayViewCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export const overlayViewControlledPropTypes = {
mapPaneName: PropTypes.string,
getPixelPositionOffset: PropTypes.func,
position: PropTypes.object,
children: PropTypes.node,
// 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
};

Expand All @@ -33,12 +39,7 @@ export default class OverlayViewCreator extends Component {
const {mapHolderRef} = overlayViewProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#OverlayView
const overlayView = new google.maps.OverlayView();
overlayView.setValues(composeOptions(overlayViewProps, [
"mapPaneName",
"getPixelPositionOffset",
"position",
"children",
]));
overlayView.setValues(composeOptions(overlayViewProps, overlayViewControlledPropTypes));

overlayView.onAdd = function () {
this._containerElement = document.createElement("div");
Expand Down
13 changes: 6 additions & 7 deletions src/creators/PolygonCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const polygonControlledPropTypes = {
// 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#Polygon
draggable: PropTypes.bool,
editable: PropTypes.bool,
Expand Down Expand Up @@ -53,13 +58,7 @@ export default class PolygonCreator extends Component {
static _createPolygon (polygonProps) {
const {mapHolderRef} = polygonProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Polygon
const polygon = new google.maps.Polygon(composeOptions(polygonProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#PolygonOptions
"draggable",
"editable",
"paths",
"visible",
]));
const polygon = new google.maps.Polygon(composeOptions(polygonProps, polygonControlledPropTypes));

polygon.setMap(mapHolderRef.getMap());

Expand Down
13 changes: 6 additions & 7 deletions src/creators/PolylineCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const polylineControlledPropTypes = {
// 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#Polyline
draggable: PropTypes.bool,
editable: PropTypes.bool,
Expand Down Expand Up @@ -51,13 +56,7 @@ export default class PolylineCreator extends Component {
static _createPolyline (polylineProps) {
const {mapHolderRef} = polylineProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Polyline
const polyline = new google.maps.Polyline(composeOptions(polylineProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#PolylineOptions
"draggable",
"editable",
"path",
"visible",
]));
const polyline = new google.maps.Polyline(composeOptions(polylineProps, polylineControlledPropTypes));

polyline.setMap(mapHolderRef.getMap());

Expand Down
13 changes: 6 additions & 7 deletions src/creators/RectangleCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const rectangleControlledPropTypes = {
// 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#Rectangle
bounds: PropTypes.any,
draggable: PropTypes.bool,
Expand Down Expand Up @@ -52,13 +57,7 @@ export default class RectangleCreator extends Component {
static _createRectangle (rectangleProps) {
const {mapHolderRef} = rectangleProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Rectangle
const rectangle = new google.maps.Rectangle(composeOptions(rectangleProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#RectangleOptions
"bounds",
"draggable",
"editable",
"visible",
]));
const rectangle = new google.maps.Rectangle(composeOptions(rectangleProps, rectangleControlledPropTypes));

rectangle.setMap(mapHolderRef.getMap());

Expand Down
8 changes: 5 additions & 3 deletions src/creators/SearchBoxCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const searchBoxControlledPropTypes = {
// NOTICE!!!!!!
//
// Only expose those with getters & setters in the table as controlled props.
//
bounds: PropTypes.any,
};

Expand All @@ -39,9 +43,7 @@ export default class SearchBoxCreator extends Component {
}

static _createSearchBox (inputElement, searchBoxProps) {
const searchBox = new google.maps.places.SearchBox(inputElement, composeOptions(searchBoxProps, [
"bounds",
]));
const searchBox = new google.maps.places.SearchBox(inputElement, composeOptions(searchBoxProps, searchBoxControlledPropTypes));

return searchBox;
}
Expand Down
10 changes: 6 additions & 4 deletions src/creators/_SkeletonCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {default as componentLifecycleDecorator} from "../utils/componentLifecycl
import {default as GoogleMapHolder} from "./GoogleMapHolder";

export const skeletonControlledPropTypes = {
// 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
animation: PropTypes.any,
};
Expand Down Expand Up @@ -44,10 +49,7 @@ export default class SkeletonCreator extends Component {
static _createSkeleton (skeletonProps) {
const {mapHolderRef} = skeletonProps;
// https://developers.google.com/maps/documentation/javascript/3.exp/reference
const skeleton = new google.maps.Skeleton(composeOptions(skeletonProps, [
// https://developers.google.com/maps/documentation/javascript/3.exp/reference
"animation",
]));
const skeleton = new google.maps.Skeleton(composeOptions(skeletonProps, skeletonControlledPropTypes));

skeleton.setMap(mapHolderRef.getMap());

Expand Down
11 changes: 7 additions & 4 deletions src/utils/composeOptions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import {default as controlledOrDefault} from "./controlledOrDefault";

export default function composeOptions (props, optionNameList) {
export default function composeOptions (props, controlledPropTypes) {
const optionNameList = Object.keys(controlledPropTypes);
const getter = controlledOrDefault(props);

// props from arguments may contain unknow props.
// We only interested those in optionNameList
return optionNameList.reduce((acc, optionName) => {
const value = getter(optionName);
if ("undefined" !== typeof value) {
acc[optionName] = value;
if ("options" !== optionName) {
const value = getter(optionName);
if ("undefined" !== typeof value) {
acc[optionName] = value;
}
}
return acc;
}, {
Expand Down

0 comments on commit 03aee4d

Please sign in to comment.