Skip to content

Commit

Permalink
Merge pull request #644 from trevtrich/master
Browse files Browse the repository at this point in the history
feat(data-fetcher): pass store to fetch trigger
  • Loading branch information
travi authored Mar 2, 2020
2 parents 1f8afb7 + 0464009 commit c8055cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [Register with the Hapi server](#register-with-the-hapi-server)
* [Optional custom renderer that passes blankie (optional to provide yourself) nonces as a prop](#optional-custom-renderer-that-passes-blankie-optional-to-provide-yourself-nonces-as-a-prop)
* [Dependencies for you to provide](#dependencies-for-you-to-provide)
* [Redial fetch trigger arguments](#redial-fetch-trigger-arguments)
* [Contribution](#contribution)
* [Install dependencies](#install-dependencies)
* [Verification](#verification)
Expand Down Expand Up @@ -48,7 +49,8 @@ to direct all `text/html` requests to this `/html` route.
In addition, [redial](https://github.com/markdalgleish/redial) `fetch` hooks
will be triggered and rendering will wait for all related requests to complete.
This enables populating the data store based on the components that are mounted
for the current route.
for the current route. See [redial arguments](#redial-fetch-trigger-arguments)
for the list of arguments supplied to triggered fetches.

### Example

Expand Down Expand Up @@ -125,6 +127,16 @@ required.
provider component.
* `render`: _optional_ custom renderer to replace the default renderer. Passed `defaultRenderer` and `request` as arguments so additional props can be passed to the defaultRenderer, potentially from the request.

### Redial fetch trigger arguments

* `params`: pass-through of react-router params taken from the path
* `dispatch`: redux store [dispatch](https://redux.js.org/api/store/#dispatchaction) method
* `state`: current state of the redux store
* `getState`: [method](https://redux.js.org/api/store/#getstate) to get the
latest state of the redux store
* `store`: the raw redux store. :warning: WARNING: this should only be used for
unique circumstances (e.g., creating a custom subscription to the store)

## Contribution

[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Expand Down
2 changes: 1 addition & 1 deletion src/data-fetcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ suite('data fetcher', () => {
const getState = sinon.stub().returns(state);
const renderProps = {...any.simpleObject(), components, params};
const store = {...any.simpleObject(), dispatch, getState};
redial.trigger.withArgs('fetch', components, {params, dispatch, state, getState}).resolves();
redial.trigger.withArgs('fetch', components, {params, dispatch, state, getState, store}).resolves();

return assert.isFulfilled(fetchData({renderProps, store}));
});
Expand Down
3 changes: 2 additions & 1 deletion src/data-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function ({renderProps, store}) {
params: renderProps.params,
dispatch: store.dispatch,
state: getState(),
getState
getState,
store
});
}

0 comments on commit c8055cd

Please sign in to comment.