Skip to content

Commit 655f143

Browse files
committed
throw an error if no callback or token is passed
update readme
1 parent a95c68e commit 655f143

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@
55

66
## Install
77

8-
TODO
8+
`yarn add react-mapkit`
99

10-
## Key generation (optional)
10+
### Key generation (optional)
1111

1212
This package includes a script you can use to generate a JWT key. To use add your private key from Apple to the keygen folder as `key.p8` then run:
1313

1414
`yarn keygen`
1515

1616
follow the prompts. The generated key can then be used for your app. If you want to generate short keys you can refer to the script in keygen to get an idea of how to do this in node.
17+
18+
## MapKit Component
19+
20+
This is the component that will render a map. You'll need to provide either a `callbackUrl` or a `token` for this component to work.
21+
22+
### Props
23+
24+
#### `callbackUrl`: string
25+
26+
a callback url that returns a JWT. More info [in Apple's docs](https://developer.apple.com/documentation/mapkitjs/mapkit/2974045-init).
27+
28+
#### `token`: string
29+
30+
a JWT token to use. Use this when using a long-lived token. In this case its probably best to make sure you set an `origin` in your token.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-mapkit",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "React wrapper for Apple's mapkit.js.",
55
"license": "MIT",
66
"main": "lib/index.js",
@@ -33,6 +33,10 @@
3333
"react": "16.x",
3434
"react-dom": "16.x"
3535
},
36+
"dependencies": {
37+
"invariant": "^2.2.4",
38+
"little-loader": "^0.2.0"
39+
},
3640
"devDependencies": {
3741
"colors": "^1.3.0",
3842
"flow-bin": "0.73.x",
@@ -64,8 +68,5 @@
6468
"maps",
6569
"mapkit",
6670
"apple"
67-
],
68-
"dependencies": {
69-
"little-loader": "^0.2.0"
70-
}
71+
]
7172
}

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as React from 'react'
44
import load from 'little-loader'
5+
import invariant from 'invariant'
56

67
type Props = {
78
/**
@@ -16,7 +17,7 @@ type State = {
1617
makKitIsStarted: boolean,
1718
}
1819

19-
export default class ComponentTemplate extends React.Component<Props, State> {
20+
export default class MapKit extends React.Component<Props, State> {
2021
map = null
2122

2223
state = {
@@ -36,6 +37,13 @@ export default class ComponentTemplate extends React.Component<Props, State> {
3637
)
3738
}
3839

40+
static getDerivedStateFromProps(props: Props, state: State) {
41+
invariant(
42+
props.callbackUrl || props.token,
43+
'Either a `callbackUrl` or `token` is required for the `MapKit` component.',
44+
)
45+
}
46+
3947
componentDidUpdate() {
4048
if (this.state.mapKitIsReady && !this.state.makKitIsStarted) {
4149
mapkit.init({

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4073,7 +4073,7 @@ [email protected]:
40734073
dependencies:
40744074
meow "^3.3.0"
40754075

4076-
invariant@^2.2.2:
4076+
invariant@^2.2.2, invariant@^2.2.4:
40774077
version "2.2.4"
40784078
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
40794079
dependencies:

0 commit comments

Comments
 (0)