Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Mar 7, 2017
1 parent 7660df7 commit 3a53076
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 12 deletions.
51 changes: 46 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@ This project is an exploration of possible ways of splitting responsibility duri

## Links

- [Documentation][doc-link]
#### Showcase

- [Documentation Site][doc-link]
- [Documentation Source](https://github.com/yeojz/react-form-addons/tree/master/site)

#### Core Methods

- [compose](https://yeojz.github.io/react-form-addons#compose)
- [withProps](https://yeojz.github.io/react-form-addons#withProps)
- [withState](https://yeojz.github.io/react-form-addons#withState)
- [withSideEffects](https://yeojz.github.io/react-form-addons#withSideEffects)
- [withValidation](https://yeojz.github.io/react-form-addons#withValidation)
- [branch](https://yeojz.github.io/react-form-addons#branch)
- [collection](https://yeojz.github.io/react-form-addons#collection)

#### Library Support
- [withReduxState](https://yeojz.github.io/react-form-addons#withReduxState) (Redux)

## Installation

Install the library:
Expand All @@ -45,8 +60,8 @@ const Form = (props) => (
);

export default compose(
withState(),
withProps()
withState(),
withProps()
)(Form);
```

Expand Down Expand Up @@ -96,12 +111,38 @@ can become

```js
export default compose(
withReduxState(),
withLocalStorage(),
withProps()
)(Form);
```

For now, this library does not provide the `redux` connector, but it is highly possible that it'll be sheduled for a future release. PRs are welcome! :)
### Redux Support

This library also provides a component for handling state in [redux](https://github.com/reactjs/redux). You'll need to install `react-redux` as well as `redux` for it to work.

*Note:* Redux components are not under default library export. As such, you'll have to import from a sub folder. i.e.

```js
import {withReduxState, formReducer} from 'react-form-addons/lib/redux';

// Creating stores
const reducers = combineReducers({
forms: formReducer
});

const store = createStore(reducers);

// During form composition
const Form = compose(
withReduxState(),
withProps()
)(FormInputs);

// Usage (note: prop "name" is required)
<Form name='example' />
```

There is a [live example](https://yeojz.github.io/react-form-addons#withReduxState) in the documentation site.

## Prior Art

Expand Down
2 changes: 1 addition & 1 deletion site/src/components/WithReduxStateExample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getCode = () => (
withProps()
)(FormInputs);
// Usage (note: prop "name" is important)
// Usage (note: prop "name" is required)
<Form name='example' />
`
);
Expand Down
2 changes: 1 addition & 1 deletion site/src/store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {combineReducers, createStore} from 'redux';
import {reducer as formReducer} from '../../lib/redux';
import {formReducer} from '../../lib/redux';

const reducers = combineReducers({
forms: formReducer
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/redux/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export actions from './actions';
export constants from './constants';
export reducer from './reducer';
export formActions from './formActions';
export formReducer from './formReducer';
export withReduxState from './withReduxState';
6 changes: 3 additions & 3 deletions src/redux/withReduxState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {PropTypes} from 'react';
import {connect} from 'react-redux';
import get from 'lodash/get';
import noop from 'lodash/noop';
import actions from './actions';
import formActions from './formActions';

const propTypes = {
getReduxData: PropTypes.func,
Expand Down Expand Up @@ -62,8 +62,8 @@ const withReduxState = (reducerKey = 'forms') => (Component) => {
});

const mapDispatchToProps = {
onChange: actions.update,
onReset: actions.reset
onChange: formActions.update,
onReset: formActions.reset
};

return connect(mapStateToProps, mapDispatchToProps)(ComponentWithReduxState);
Expand Down
24 changes: 24 additions & 0 deletions tests/redux/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {expect} from 'chai';
import * as exposed from '../../src/redux/index';

describe('redux/index', function () {
it('total number of exports', function () {
expect(Object.keys(exposed)).to.be.length(4)
});

it('exports constants', function () {
expect(exposed.constants).to.not.be.undefined;
});

it('exports formActions', function () {
expect(exposed.formActions).to.not.be.undefined;
});

it('exports formReducer', function () {
expect(exposed.formReducer).to.not.be.undefined;
});

it('exports withReduxState', function () {
expect(exposed.withReduxState).to.not.be.undefined;
});
});

0 comments on commit 3a53076

Please sign in to comment.