Skip to content

Commit

Permalink
Merge pull request #41 from heroku/fix-identity-request-meta
Browse files Browse the repository at this point in the history
Passthrough provided meta in identity requests
  • Loading branch information
ryanbrainard committed Jan 19, 2016
2 parents 590cef5 + 930a12f commit 2be4192
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/api.md
Expand Up @@ -26,7 +26,8 @@ Instead, it *returns* a new, connected component class, for you to use.
- `andThen(value, meta): { prop: request, ... }` *(Function)*: returns an object of request mappings to fetch after fulfillment of this request but does not replace this request. Takes the `value` and `meta` of this request as arguments.
- `andCatch(reason, meta): { prop: request, ... }` *(Function)*: returns an object of request mappings to fetch after rejection of this request but does not replace this request. Takes the `value` and `meta` of this request as arguments.
- `value` *(Any)*: Data to passthrough directly to `PromiseState` as an alternative to providing a URL. This is an advanced option used for static data and data transformations.

- `meta` *(Any)*: Metadata to passthrough directly to `PromiseState`. This attribute is only recognized if `value` is also provided.

Requests specified as functions are not fetched immediately when props are received, but rather bound to the props and injected into the component to be called at a later time in response to user actions. Functions should be pure and return the same format as `mapPropsToRequestsToProps` itself. If a function maps a request to the same name as an existing prop, the prop will be overwritten. This is commonly used for taking some action that updates an existing `PromiseState`. Consider setting `refreshing: true` in such it situation.

* [`options`] *(Object)* If specified, further customizes the behavior of the connector.
Expand Down
2 changes: 1 addition & 1 deletion src/components/connect.js
Expand Up @@ -179,7 +179,7 @@ export default function connect(mapPropsToRequestsToProps, options = {}) {
const onRejection = this.createPromiseStateOnRejection(prop, mapping, startedAt)

if (mapping.value) {
const meta = {}
const meta = mapping.meta || {}
this.setAtomicState(prop, startedAt, mapping, initPS(meta))
return Promise.resolve(mapping.value).then(onFulfillment(meta), onRejection(meta))
} else {
Expand Down
6 changes: 3 additions & 3 deletions test/components/connect.spec.js
Expand Up @@ -181,7 +181,7 @@ describe('React', () => {
})

it('should passthrough value of identity requests', (done) => {
@connect(() => ({ testFetch: { value: 'foo' } }))
@connect(() => ({ testFetch: { value: 'foo', meta: 'voodoo' } }))
class Container extends Component {
render() {
return <Passthrough {...this.props} />
Expand All @@ -197,7 +197,7 @@ describe('React', () => {

const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
expect(stub.props.testFetch).toIncludeKeyValues({
fulfilled: false, pending: true, refreshing: false, reason: null, rejected: false, settled: false, value: null
fulfilled: false, pending: true, refreshing: false, reason: null, rejected: false, settled: false, value: null, meta: 'voodoo'
})

setImmediate(() => {
Expand All @@ -206,7 +206,7 @@ describe('React', () => {

const stub = TestUtils.findRenderedComponentWithType(container, Passthrough)
expect(stub.props.testFetch).toIncludeKeyValues({
fulfilled: true, pending: false, refreshing: false, reason: null, rejected: false, settled: true, value: 'foo'
fulfilled: true, pending: false, refreshing: false, reason: null, rejected: false, settled: true, value: 'foo', meta: 'voodoo'
})
done()
})
Expand Down

0 comments on commit 2be4192

Please sign in to comment.