Skip to content

Commit ec4f0e7

Browse files
authored
Merge pull request #74 from ubilabs/fix/export-new-hooks
fix(index): export default elevation and maxzoom hook
2 parents 303148e + bea4ee8 commit ec4f0e7

File tree

12 files changed

+1948
-776
lines changed

12 files changed

+1948
-776
lines changed

.eslintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"plugins": ["react", "import", "react-hooks", "@typescript-eslint"],
2+
"plugins": ["react", "import", "react-hooks", "@typescript-eslint", "codegen"],
33
"extends": ["prettier", "plugin:@typescript-eslint/recommended"],
44
"parser": "@typescript-eslint/parser",
55
"env": {
@@ -320,6 +320,7 @@
320320
"@typescript-eslint/explicit-function-return-type": 0,
321321
"@typescript-eslint/no-empty-function": 0,
322322
"@typescript-eslint/no-unused-vars": ["error"],
323-
"@typescript-eslint/no-use-before-define": ["error"]
323+
"@typescript-eslint/no-use-before-define": ["error"],
324+
"codegen/codegen": "error"
324325
}
325326
}

package-lock.json

Lines changed: 1893 additions & 715 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
"url": "git://github.com/ubilabs/google-maps-react-hooks.git"
1313
},
1414
"scripts": {
15-
"build": "rm -rf dist/* && microbundle -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
16-
"dev": "rm -rf dist/* && microbundle watch -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
15+
"build": "npm run barrel && npm run microbundle:build",
16+
"start": "npm run barrel:watch && npm run mircobundle:dev",
17+
"microbundle:build": "rm -rf dist/* && microbundle -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
18+
"microbundle:dev": "rm -rf dist/* && microbundle watch -o dist/index.js -f modern,umd --external react=React --sourcemap false --jsx React.createElement --no-compress --tsconfig ./tsconfig.json",
1719
"lint": "eslint './{src,examples}/**/*.{ts,tsx}'",
1820
"types": "tsc --project tsconfig.json --noEmit",
1921
"test": "npm run lint && npm run types",
@@ -22,6 +24,8 @@
2224
"preversion": "npm run test",
2325
"version": "npm run changelog && git checkout -b chore/release-${npm_package_version} && git add .",
2426
"postversion": "git push -u origin chore/release-${npm_package_version} && git push --tags --no-verify",
27+
"barrel": "eslint --fix src/index.ts",
28+
"barrel:watch": "nodemon --delay 1 -e ts,tsx --watch src/hooks -x 'npm run barrel --silent || exit 1'",
2529
"postinstall": "npm install --prefix examples",
2630
"start:sample-map": "cd examples && npm run clean-examples && npm run start:map",
2731
"start:map-with-markers": "cd examples && npm run clean-examples && npm run start:map-markers",
@@ -46,11 +50,13 @@
4650
"conventional-changelog-cli": "^2.1.1",
4751
"eslint": "^8.25.0",
4852
"eslint-config-prettier": "^8.3.0",
53+
"eslint-plugin-codegen": "^0.16.1",
4954
"eslint-plugin-import": "^2.23.4",
5055
"eslint-plugin-prettier": "^4.2.1",
5156
"eslint-plugin-react": "^7.24.0",
5257
"eslint-plugin-react-hooks": "^4.2.0",
5358
"microbundle": "^0.15.1",
59+
"nodemon": "^2.0.20",
5460
"prettier": "^2.3.2",
5561
"typescript": "^4.3.5"
5662
},

src/hooks/autocomplete.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {useState, useRef, useEffect} from 'react';
22

3-
import useGoogleMap from './map-instance';
3+
import {useGoogleMap} from './map-instance';
44

5-
interface AutocompleteProps {
5+
export interface AutocompleteProps {
66
inputField: HTMLInputElement | null;
77
options?: google.maps.places.AutocompleteOptions;
88
onPlaceChanged: (place: google.maps.places.PlaceResult) => void;
@@ -12,7 +12,7 @@ interface AutocompleteProps {
1212
* Hook to get a Google Maps Places Autocomplete instance
1313
* monitoring an input field
1414
*/
15-
const useAutocomplete = (
15+
export const useAutocomplete = (
1616
props: AutocompleteProps
1717
): google.maps.places.Autocomplete | null => {
1818
const {inputField, options, onPlaceChanged} = props;
@@ -57,5 +57,3 @@ const useAutocomplete = (
5757

5858
return autocomplete;
5959
};
60-
61-
export default useAutocomplete;

src/hooks/directions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {useMemo, useEffect, useCallback} from 'react';
22

3-
import useGoogleMap from './map-instance';
3+
import {useGoogleMap} from './map-instance';
44

5-
interface DirectionsProps {
5+
export interface DirectionsProps {
66
renderOnMap?: boolean;
77
renderOptions?: google.maps.DirectionsRendererOptions;
88
}
@@ -25,7 +25,9 @@ interface DirectionsHookReturns {
2525
/**
2626
* Hook to get Google Maps Places Directions Service instance
2727
*/
28-
const useDirections = (props: DirectionsProps = {}): DirectionsHookReturns => {
28+
export const useDirections = (
29+
props: DirectionsProps = {}
30+
): DirectionsHookReturns => {
2931
const {renderOnMap, renderOptions} = props;
3032
const {map, loading} = useGoogleMap();
3133

@@ -131,5 +133,3 @@ const useDirections = (props: DirectionsProps = {}): DirectionsHookReturns => {
131133
renderRouteOfIndex
132134
};
133135
};
134-
135-
export default useDirections;

src/hooks/distance-matrix.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {useMemo} from 'react';
22

3-
import useGoogleMap from './map-instance';
3+
import {useGoogleMap} from './map-instance';
44

55
/**
66
* Hook to get Distance Matrix Service instance
77
*/
8-
const useDistanceMatrix =
8+
export const useDistanceMatrix =
99
(): google.maps.DistanceMatrixService | null => {
1010
const {map} = useGoogleMap();
1111

@@ -26,5 +26,3 @@ const useDistanceMatrix =
2626

2727
return distanceMatrixService;
2828
};
29-
30-
export default useDistanceMatrix;

src/hooks/elevation.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import {useMemo} from 'react';
22

3-
import useGoogleMap from './map-instance';
3+
import {useGoogleMap} from './map-instance';
44

55
/**
66
* Hook to get Elevation Service instance
77
*/
8-
const useElevationService = (): google.maps.ElevationService | null => {
8+
export const useElevationService = (): google.maps.ElevationService | null => {
99
const {map} = useGoogleMap();
1010

1111
// Creates an Elevation Service instance
12-
const elevationService =
13-
useMemo<google.maps.ElevationService | null>(() => {
14-
// Wait for map to be initialized
15-
if (!map) {
16-
return null;
17-
}
12+
const elevationService = useMemo<google.maps.ElevationService | null>(() => {
13+
// Wait for map to be initialized
14+
if (!map) {
15+
return null;
16+
}
1817

19-
return new google.maps.ElevationService();
20-
}, [map]);
18+
return new google.maps.ElevationService();
19+
}, [map]);
2120

2221
return elevationService;
2322
};
24-
25-
export default useElevationService;

src/hooks/geocoder.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {useMemo} from 'react';
22

3-
import useGoogleMap from './map-instance';
3+
import {useGoogleMap} from './map-instance';
44

55
/**
66
* Hook to get Google Maps Geocoder instance
77
*/
8-
const useGeocoder = (): google.maps.Geocoder | null => {
8+
export const useGeocoder = (): google.maps.Geocoder | null => {
99
const {map} = useGoogleMap();
1010

1111
// Creates a Geocoder instance
@@ -20,5 +20,3 @@ const useGeocoder = (): google.maps.Geocoder | null => {
2020

2121
return geocoder;
2222
};
23-
24-
export default useGeocoder;

src/hooks/map-instance.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ import {GoogleMapContext, GoogleMapContextType} from '../map-provider';
55
/**
66
* Hook to get global map instance
77
*/
8-
const useGoogleMap = (): GoogleMapContextType => useContext(GoogleMapContext);
9-
10-
export default useGoogleMap;
8+
export const useGoogleMap = (): GoogleMapContextType =>
9+
useContext(GoogleMapContext);

src/hooks/max-zoom.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import {useMemo} from 'react';
22

3-
import useGoogleMap from './map-instance';
3+
import {useGoogleMap} from './map-instance';
44

55
/**
66
* Hook to get Max Zoom Service instance
77
*/
8-
const useMaxZoomService = (): google.maps.MaxZoomService | null => {
8+
export const useMaxZoomService = (): google.maps.MaxZoomService | null => {
99
const {map} = useGoogleMap();
1010

1111
// Creates a Max Zoom Service instance
12-
const maxZoomService =
13-
useMemo<google.maps.MaxZoomService | null>(() => {
14-
// Wait for map to be initialized
15-
if (!map) {
16-
return null;
17-
}
12+
const maxZoomService = useMemo<google.maps.MaxZoomService | null>(() => {
13+
// Wait for map to be initialized
14+
if (!map) {
15+
return null;
16+
}
1817

19-
return new google.maps.MaxZoomService();
20-
}, [map]);
18+
return new google.maps.MaxZoomService();
19+
}, [map]);
2120

2221
return maxZoomService;
2322
};
24-
25-
export default useMaxZoomService;

0 commit comments

Comments
 (0)