Skip to content

Commit

Permalink
Merge pull request #4 from conveyal/dev
Browse files Browse the repository at this point in the history
Rearrange and republish for smarter imports
  • Loading branch information
trevorgerhardt authored Nov 14, 2016
2 parents 1411dd9 + d448c58 commit 4a5ebcb
Show file tree
Hide file tree
Showing 27 changed files with 323 additions and 400 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ before_install:
install:
- yarn
script:
- yarn run clean
- yarn run cover
- codecov
after_success:
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
Modern JavaScript applications take a lot of bootstrapping. This library helps with some common libs to include and use on the client to help.

## Pronunciation

"Woonerf" is a Dutch word for a small neighborhood street where vehicles must move very slowly. The kind of road you can imagine allowing kids to play in. Although it's fun to pronounce it as "woo nerf", the break is after the n (woon == living, erf == yard). A good transliteration for an American English speaker would be "Vone Airf".

## Usage

Let's create a Redux application:

```js
const {mount} = require('@conveyal/reboot')
const mount = require('@conveyal/woonerf/mount')

const Application = require('./containers/application')
const reducers = require('./reducers')
Expand All @@ -30,6 +34,10 @@ This will create a redux store with the `fetch`, `history`, `logger`, `multi`, a

### `auth0`

```js
const
```

### `fetch({url, options, next})`

### `html({title})`
Expand All @@ -40,8 +48,8 @@ This will create a redux store with the `fetch`, `history`, `logger`, `multi`, a

With [yarn](https://yarnpkg.com/) installed, run

```
$ yarn add @conveyal/reboot
```sh
$ yarn add @conveyal/woonerf
```

## See Also
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion __tests__/lib/icon.js → __tests__/lib/components/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import {mount} from 'enzyme'
import {mountToJson} from 'enzyme-to-json'

import {Icon} from '../../lib'
import {Icon} from '../../../src'

describe('Icon', () => {
it('should return an Icon element with a given type', () => {
Expand Down
10 changes: 1 addition & 9 deletions __tests__/lib/pure.js → __tests__/lib/components/pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import {mount} from 'enzyme'
import {mountToJson} from 'enzyme-to-json'

import {Pure} from '../../lib'
import {Pure} from '../../../src'

class PureTest extends Pure {}
PureTest.prototype.render = jest.fn(() => <div />)
Expand All @@ -13,12 +13,4 @@ describe('Pure', () => {
it('should return an Pure element with a given type', () => {
expect(mountToJson(mount(<PureTest />))).toMatchSnapshot()
})

it.skip('TODO: should not re-render when the props have not changed', () => {

})

it.skip('TODO: should re-render when the props have changed', () => {

})
})
4 changes: 2 additions & 2 deletions __tests__/lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import isObject from 'lodash.isobject'

import fetch from '../../lib/fetch'
import createStore from '../../lib/store'
import fetch from '../../src/fetch'
import createStore from '../../src/store'

const store = createStore()

Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/html.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals describe, expect, it */

import html from '../../lib/html'
import html from '../../src/html'

describe('html', () => {
it('should return an HTML string with a given title', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {Component, PropTypes} from 'react'
import {mount} from 'enzyme'
import {mountToJson} from 'enzyme-to-json'

import {create} from '../../lib/mount'
import {create} from '../../src/mount'

class App extends Component {
static propTypes = {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/lib/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('store', () => {
it('should create a development redux store with the reducers passed', () => {
jest.resetModules()
process.env.NODE_ENV = 'development'
const createStore = require('../../../lib/store')
const createStore = require('../../../src/store')
const store = createStore({})

expect(store.dispatch).toBeDefined()
Expand All @@ -15,7 +15,7 @@ describe('store', () => {
it('should create a production redux store with the reducers passed', () => {
jest.resetModules()
process.env.NODE_ENV = 'production'
const createStore = require('../../../lib/store')
const createStore = require('../../../src/store')
const store = createStore({})

expect(store.dispatch).toBeDefined()
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/store/multi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals describe, expect, it, jest */

import multi from '../../../lib/store/multi'
import multi from '../../../src/store/multi'

describe('store > multi', () => {
it('should call dispatch on every action in the array', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/store/promise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals describe, expect, it, jest */

import promise from '../../../lib/store/promise'
import promise from '../../../src/store/promise'

describe('store > promise', () => {
it('should call dispatch on the resolved value of a promise', async () => {
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@conveyal/woonerf",
"description": "React/Redux bootstrapping and common libs for Conveyal",
"main": "./build/lib",
"main": "index.js",
"repository": {
"url": "https://github.com/conveyal/woonerf",
"type": "git"
},
"scripts": {
"cover": "mastarm lint && NODE_ENV=test mastarm test --coverage --coverage-paths lib",
"prepublish": "mastarm prepublish lib",
"cover": "mastarm lint && NODE_ENV=test mastarm test --coverage --coverage-paths src",
"clean": "rm -r components store ./*.js ./*.js.map",
"prepublish": "mastarm prepublish src --outdir ./",
"test": "mastarm lint && NODE_ENV=test mastarm test",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
Expand All @@ -24,6 +25,7 @@
"react": "^15.3.2",
"react-addons-perf": "^15.3.2",
"react-dom": "^15.3.2",
"react-redux": "^4.4.5",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.6",
"redux": "^3.6.0",
Expand All @@ -33,7 +35,7 @@
"devDependencies": {
"enzyme": "^2.5.1",
"enzyme-to-json": "^1.1.5",
"mastarm": "^1.3.0",
"mastarm": "^3.0.0",
"react-addons-test-utils": "^15.3.2",
"semantic-release": "^4.3.5"
},
Expand Down
49 changes: 0 additions & 49 deletions lib/auth0.js → src/auth0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Auth0Lock from 'auth0-lock'
import Auth0Client from 'auth0-js'
import {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import {push} from 'react-router-redux'
import {createAction} from 'redux-actions'

Expand Down Expand Up @@ -58,50 +56,3 @@ export function refreshUser (dispatch) {
}
}
}

class Auth0 extends Component {
static propTypes = {
push: PropTypes.func.isRequired,
setAuth0User: PropTypes.func.isRequired
}

_authenticated = (authResult) => {
const {push, setAuth0User} = this.props
lock.getProfile(authResult.idToken, (error, profile) => {
if (error) {
setAuth0User(null)
push('/login')
} else {
const user = {
...authResult,
profile
}
localStorage.setItem('user', JSON.stringify(user))
setAuth0User(user)
push('/')
}
})
}

componentDidMount () {
// when testing, auth0 credentials are not currently entered, so `lock` will be null
if (lock) {
lock.show()
lock.on('authenticated', this._authenticated)
}
}

render () {
return null
}
}

function mapStateToProps (state) {
return state
}
const mapDispatchToProps = {
push,
setAuth0User
}

export default connect(mapStateToProps, mapDispatchToProps)(Auth0)
55 changes: 55 additions & 0 deletions src/components/auth0-lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {PropTypes} from 'react'
import {connect} from 'react-redux'
import {push} from 'react-router-redux'

import {lock, setAuth0User} from '../auth0'
import Pure from './pure'

const localStorage = window.localStorage

class Auth0 extends Pure {
static propTypes = {
push: PropTypes.func.isRequired,
setAuth0User: PropTypes.func.isRequired
}

_authenticated = (authResult) => {
const {push, setAuth0User} = this.props
lock.getProfile(authResult.idToken, (error, profile) => {
if (error) {
setAuth0User(null)
push('/login')
} else {
const user = {
...authResult,
profile
}
localStorage.setItem('user', JSON.stringify(user))
setAuth0User(user)
push('/')
}
})
}

componentDidMount () {
// when testing, auth0 credentials are not currently entered, so `lock` will be null
if (lock) {
lock.show()
lock.on('authenticated', this._authenticated)
}
}

render () {
return null
}
}

function mapStateToProps (state) {
return state
}
const mapDispatchToProps = {
push,
setAuth0User
}

export default connect(mapStateToProps, mapDispatchToProps)(Auth0)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions lib/index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = {
auth0: require('./auth0'),
Auth0Lock: require('./components/auth0-lock'),
fetch: require('./fetch'),
html: require('./html'),
Icon: require('./icon'),
Icon: require('./components/icon'),
mount: require('./mount'),
Pure: require('./pure'),
Pure: require('./components/pure'),
store: require('./store')
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4a5ebcb

Please sign in to comment.