Skip to content

Commit 591a09b

Browse files
author
Trevor Richardson
committed
feat(data-fetcher): pass store to fetch trigger
- in some circumstances a consumer needs direct access to the store (e.g., creating a custom subscription) so we now provide this. this should only be used when absolutely needed.
1 parent 7879aec commit 591a09b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ to direct all `text/html` requests to this `/html` route.
4848
In addition, [redial](https://github.com/markdalgleish/redial) `fetch` hooks
4949
will be triggered and rendering will wait for all related requests to complete.
5050
This enables populating the data store based on the components that are mounted
51-
for the current route.
51+
for the current route. See [redial arguments](#redial-fetch-trigger-arguments)
52+
for the list of arguments supplied to triggered fetches.
5253

5354
### Example
5455

@@ -125,6 +126,15 @@ required.
125126
provider component.
126127
* `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.
127128

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

130140
[![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)