From 591a09bdd18d7c4953a687801746d305327ccc20 Mon Sep 17 00:00:00 2001 From: Trevor Richardson Date: Mon, 2 Mar 2020 14:20:56 -0800 Subject: [PATCH 1/3] 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. --- README.md | 12 +++++++++++- src/data-fetcher-test.js | 2 +- src/data-fetcher.js | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4d51e77..bee7a1dc 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,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 @@ -125,6 +126,15 @@ 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: 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/) diff --git a/src/data-fetcher-test.js b/src/data-fetcher-test.js index dee21581..7d674abf 100644 --- a/src/data-fetcher-test.js +++ b/src/data-fetcher-test.js @@ -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})); }); diff --git a/src/data-fetcher.js b/src/data-fetcher.js index 60ffb8e4..4e7fe86a 100644 --- a/src/data-fetcher.js +++ b/src/data-fetcher.js @@ -7,6 +7,7 @@ export default function ({renderProps, store}) { params: renderProps.params, dispatch: store.dispatch, state: getState(), - getState + getState, + store }); } From 57f5d4e7eefef6f39e7ef5633a11bc6039450b80 Mon Sep 17 00:00:00 2001 From: Trevor Richardson Date: Mon, 2 Mar 2020 14:39:34 -0800 Subject: [PATCH 2/3] docs(readme): update toc with redial fetch arguments --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bee7a1dc..71c86c1a 100644 --- a/README.md +++ b/README.md @@ -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) @@ -127,13 +128,14 @@ required. * `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 + latest state of the redux store * `store`: the raw redux store. WARNING: this should only be used for unique -circumstances (e.g., creating a custom subscription to the store) + circumstances (e.g., creating a custom subscription to the store) ## Contribution From 04640092496330da816eca8e56ffb07cdcf6ce75 Mon Sep 17 00:00:00 2001 From: Trevor Richardson Date: Mon, 2 Mar 2020 14:43:16 -0800 Subject: [PATCH 3/3] docs(readme): add warning icon to raw store warning --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71c86c1a..fcd3c422 100644 --- a/README.md +++ b/README.md @@ -134,8 +134,8 @@ required. * `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: this should only be used for unique - circumstances (e.g., creating a custom subscription to the 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