Skip to content

Commit

Permalink
throw an error if no callback or token is passed
Browse files Browse the repository at this point in the history
update readme
  • Loading branch information
chrisdrackett committed Jun 7, 2018
1 parent a95c68e commit 655f143
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@

## Install

TODO
`yarn add react-mapkit`

## Key generation (optional)
### Key generation (optional)

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:

`yarn keygen`

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.

## MapKit Component

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.

### Props

#### `callbackUrl`: string

a callback url that returns a JWT. More info [in Apple's docs](https://developer.apple.com/documentation/mapkitjs/mapkit/2974045-init).

#### `token`: string

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.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-mapkit",
"version": "0.1.0",
"version": "0.1.1",
"description": "React wrapper for Apple's mapkit.js.",
"license": "MIT",
"main": "lib/index.js",
Expand Down Expand Up @@ -33,6 +33,10 @@
"react": "16.x",
"react-dom": "16.x"
},
"dependencies": {
"invariant": "^2.2.4",
"little-loader": "^0.2.0"
},
"devDependencies": {
"colors": "^1.3.0",
"flow-bin": "0.73.x",
Expand Down Expand Up @@ -64,8 +68,5 @@
"maps",
"mapkit",
"apple"
],
"dependencies": {
"little-loader": "^0.2.0"
}
]
}
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as React from 'react'
import load from 'little-loader'
import invariant from 'invariant'

type Props = {
/**
Expand All @@ -16,7 +17,7 @@ type State = {
makKitIsStarted: boolean,
}

export default class ComponentTemplate extends React.Component<Props, State> {
export default class MapKit extends React.Component<Props, State> {
map = null

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

static getDerivedStateFromProps(props: Props, state: State) {
invariant(
props.callbackUrl || props.token,
'Either a `callbackUrl` or `token` is required for the `MapKit` component.',
)
}

componentDidUpdate() {
if (this.state.mapKitIsReady && !this.state.makKitIsStarted) {
mapkit.init({
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,7 @@ [email protected]:
dependencies:
meow "^3.3.0"

invariant@^2.2.2:
invariant@^2.2.2, invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
dependencies:
Expand Down

0 comments on commit 655f143

Please sign in to comment.