Skip to content

Commit 3713bd1

Browse files
authored
Merge pull request ordazgustavo#7 from ordazgustavo/chore/enable-ts-strict-mode
chore: re enable typescript strict mode
2 parents 9292b0d + 28cdabb commit 3713bd1

File tree

6 files changed

+36
-51
lines changed

6 files changed

+36
-51
lines changed

src/Circle.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ export class Circle extends React.Component<CircleProps> {
1717
radius: 1000,
1818
strokeColor: 'black',
1919
}
20+
public context!: HEREMapContext
2021

21-
public context: HEREMapContext
22-
23-
private circle: H.map.Circle
22+
private circle?: H.map.Circle
2423

2524
public componentDidUpdate(prevProps: CircleProps) {
2625
if (prevProps.lat !== this.props.lat || prevProps.lng !== this.props.lng) {
@@ -43,16 +42,6 @@ export class Circle extends React.Component<CircleProps> {
4342
}
4443
}
4544

46-
public render() {
47-
const { map } = this.context
48-
49-
if (map && !this.circle) {
50-
this.addCircleToMap()
51-
}
52-
53-
return null
54-
}
55-
5645
private addCircleToMap() {
5746
const { map } = this.context
5847

@@ -79,12 +68,26 @@ export class Circle extends React.Component<CircleProps> {
7968
}
8069
}
8170

82-
private setCenter(point: H.geo.IPoint): void {
83-
this.circle.setCenter(point)
71+
private setCenter(point: H.geo.IPoint) {
72+
if (this.circle) {
73+
this.circle.setCenter(point)
74+
}
8475
}
8576

86-
private setRadius(radius: number): void {
87-
this.circle.setRadius(radius)
77+
private setRadius(radius: number) {
78+
if (this.circle) {
79+
this.circle.setRadius(radius)
80+
}
81+
}
82+
83+
public render() {
84+
const { map } = this.context
85+
86+
if (map && !this.circle) {
87+
this.addCircleToMap()
88+
}
89+
90+
return null
8891
}
8992
}
9093

src/HEREMap.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,12 @@ export interface HEREMapProps extends H.Map.Options {
3131

3232
export interface OwnState {}
3333

34-
type State = OwnState & HEREMapContext
35-
36-
export class HEREMap extends React.Component<HEREMapProps, State> {
37-
public state: State = {
38-
map: null,
39-
behavior: null,
40-
ui: null,
41-
}
34+
export class HEREMap extends React.Component<HEREMapProps, HEREMapContext> {
4235
private debouncedResizeMap: any
43-
public static contextType = MapContext
44-
public context: HEREMapContext
36+
// public static contextType = MapContext
4537

46-
constructor(props: HEREMapProps, context: HEREMapContext) {
47-
super(props, context)
38+
constructor(props: HEREMapProps) {
39+
super(props)
4840

4941
this.debouncedResizeMap = debounce(this.resizeMap, 200)
5042
}
@@ -114,11 +106,7 @@ export class HEREMap extends React.Component<HEREMapProps, State> {
114106

115107
const mapElement = document.querySelector('.map-container')
116108

117-
const HERE: HEREMapContext = {
118-
map: null,
119-
behavior: null,
120-
ui: null,
121-
}
109+
const HERE: HEREMapContext = {}
122110

123111
let layer = defaultLayers.normal.map
124112
if (setLayer) {
@@ -149,22 +137,22 @@ export class HEREMap extends React.Component<HEREMapProps, State> {
149137

150138
public setCenter(point: H.geo.IPoint): void {
151139
const { animateCenter } = this.props
152-
const { map } = this.context
140+
const { map } = this.state
153141
if (map) {
154142
map.setCenter(point, animateCenter === true)
155143
}
156144
}
157145

158146
public setZoom(zoom: number): void {
159147
const { animateZoom } = this.props
160-
const { map } = this.context
148+
const { map } = this.state
161149
if (map) {
162150
map.setZoom(zoom, animateZoom === true)
163151
}
164152
}
165153

166154
private resizeMap = () => {
167-
const { map } = this.context
155+
const { map } = this.state
168156
if (map) {
169157
map.getViewPort().resize()
170158
}

src/Marker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface MarkerProps extends H.map.Marker.Options, H.geo.IPoint {
2222

2323
export class Marker extends React.Component<MarkerProps> {
2424
public static contextType = MapContext
25-
public context: HEREMapContext
25+
public context!: HEREMapContext
2626
private marker?: H.map.DomMarker | H.map.Marker
2727

2828
public componentDidMount() {

src/RouteLine.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ export interface RouteLineProps extends H.map.Polyline.Options, H.geo.IPoint {
1010
shape: Shape
1111
}
1212

13-
class RouteLine extends React.Component<RouteLineProps, object> {
13+
class RouteLine extends React.Component<RouteLineProps> {
1414
public static contextType = MapContext
15-
16-
public context: HEREMapContext
17-
15+
public context!: HEREMapContext
1816
private routeLine?: H.map.Polyline
1917

2018
public componentDidUpdate(prevProps: RouteLineProps) {

src/utils/map-context.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import React from 'react'
22

33
export interface HEREMapContext {
4-
map: H.Map | null
5-
behavior: H.mapevents.Behavior | null
6-
ui: H.ui.UI | null
4+
map?: H.Map
5+
behavior?: H.mapevents.Behavior
6+
ui?: H.ui.UI
77
}
88

9-
const MapContext = React.createContext<HEREMapContext>({
10-
map: null,
11-
behavior: null,
12-
ui: null,
13-
})
9+
const MapContext = React.createContext({} as HEREMapContext)
1410

1511
export default MapContext

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"allowJs": false,
99
"jsx": "react",
1010
"allowSyntheticDefaultImports": true,
11-
// "strict": true,
11+
"strict": true,
1212
"declaration": true,
1313
"moduleResolution": "node",
1414
"forceConsistentCasingInFileNames": true,

0 commit comments

Comments
 (0)