File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -41,16 +41,17 @@ interface GeolocatedProps {
41
41
positionError ?: PositionError ;
42
42
}
43
43
44
- declare class ElementClass extends React . Component < GeolocatedProps , any > { }
45
- interface ClassDecorator {
46
- < T extends ( typeof ElementClass ) > ( component : T ) : T ;
44
+ type ComponentType = React . ComponentClass < GeolocatedProps > | React . StatelessComponent < GeolocatedProps > ;
45
+
46
+ interface ComponentDecorator {
47
+ < TargetClass extends ComponentType > ( component : TargetClass ) : TargetClass ;
47
48
}
48
49
49
50
/**
50
51
* The HOC function.
51
52
*/
52
- export function geolocated ( config ?: GeolocatedConfig ) : ClassDecorator ;
53
+ export function geolocated ( config ?: GeolocatedConfig ) : ComponentDecorator ;
53
54
/**
54
55
* React propTypes object.
55
56
*/
56
- export const geoPropTypes : React . ValidationMap < ElementClass > ;
57
+ export const geoPropTypes : React . ValidationMap < ComponentType > ;
Original file line number Diff line number Diff line change 6
6
"version" : " 0.0.0-semantic-release" ,
7
7
"scripts" : {
8
8
"start" : " webpack-dev-server" ,
9
- "test" : " jest --coverage" ,
9
+ "test" : " npm run test:lint && npm run test:js && npm run test:ts" ,
10
+ "test:js" : " jest --coverage" ,
10
11
"test:tdd" : " jest --watch" ,
11
12
"test:lint" : " eslint . --ext .js --ext .jsx --ignore-path .gitignore --ignore-pattern dist --ignore-pattern docs --cache" ,
12
13
"test:ts" : " cd tests/typescript && rimraf out && rimraf typings && typings install && tsc && rimraf out && rimraf typings" ,
77
78
],
78
79
"license" : " MIT" ,
79
80
"pre-push" : [
80
- " test" ,
81
+ " test:js " ,
81
82
" test:lint"
82
83
],
83
84
"config" : {
Original file line number Diff line number Diff line change @@ -14,6 +14,17 @@ class Demo extends React.Component<IDemoProps, {}> {
14
14
}
15
15
}
16
16
17
+ function StatelessDemo ( props : GeolocatedProps ) : React . ReactElement < { } > {
18
+ return < div >
19
+ latitude: { props . coords && props . coords . latitude }
20
+ isGeolocationAvailable: { props . isGeolocationAvailable }
21
+ isGeolocationEnabled: { props . isGeolocationEnabled }
22
+ positionError: { props . positionError }
23
+ </ div > ;
24
+ }
25
+
26
+ const StatelessDemoWrapped = geolocated ( ) ( StatelessDemo ) ;
27
+
17
28
export default geolocated ( {
18
29
userDecisionTimeout : 5000 ,
19
30
positionOptions : {
You can’t perform that action at this time.
0 commit comments