Skip to content

Commit c8055cd

Browse files
authored
Merge pull request #644 from trevtrich/master
feat(data-fetcher): pass store to fetch trigger
2 parents 1f8afb7 + 0464009 commit c8055cd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [Register with the Hapi server](#register-with-the-hapi-server)
1717
* [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)
1818
* [Dependencies for you to provide](#dependencies-for-you-to-provide)
19+
* [Redial fetch trigger arguments](#redial-fetch-trigger-arguments)
1920
* [Contribution](#contribution)
2021
* [Install dependencies](#install-dependencies)
2122
* [Verification](#verification)
@@ -48,7 +49,8 @@ to direct all `text/html` requests to this `/html` route.
4849
In addition, [redial](https://github.com/markdalgleish/redial) `fetch` hooks
4950
will be triggered and rendering will wait for all related requests to complete.
5051
This enables populating the data store based on the components that are mounted
51-
for the current route.
52+
for the current route. See [redial arguments](#redial-fetch-trigger-arguments)
53+
for the list of arguments supplied to triggered fetches.
5254

5355
### Example
5456

@@ -125,6 +127,16 @@ required.
125127
provider component.
126128
* `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.
127129

130+
### Redial fetch trigger arguments
131+
132+
* `params`: pass-through of react-router params taken from the path
133+
* `dispatch`: redux store [dispatch](https://redux.js.org/api/store/#dispatchaction) method
134+
* `state`: current state of the redux store
135+
* `getState`: [method](https://redux.js.org/api/store/#getstate) to get the
136+
latest state of the redux store
137+
* `store`: the raw redux store. :warning: WARNING: this should only be used for
138+
unique circumstances (e.g., creating a custom subscription to the store)
139+
128140
## Contribution
129141

130142
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

src/data-fetcher-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite('data fetcher', () => {
2323
const getState = sinon.stub().returns(state);
2424
const renderProps = {...any.simpleObject(), components, params};
2525
const store = {...any.simpleObject(), dispatch, getState};
26-
redial.trigger.withArgs('fetch', components, {params, dispatch, state, getState}).resolves();
26+
redial.trigger.withArgs('fetch', components, {params, dispatch, state, getState, store}).resolves();
2727

2828
return assert.isFulfilled(fetchData({renderProps, store}));
2929
});

src/data-fetcher.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function ({renderProps, store}) {
77
params: renderProps.params,
88
dispatch: store.dispatch,
99
state: getState(),
10-
getState
10+
getState,
11+
store
1112
});
1213
}

0 commit comments

Comments
 (0)