Skip to content

Commit

Permalink
feat(redux): deprecate config value "shouldPrefetchOnServer"
Browse files Browse the repository at this point in the history
And put its successor `allowServerSideDataFetching` into place.
  • Loading branch information
Emanuel Kluge authored and jhiode committed Oct 28, 2019
1 parent 8cea9dc commit 2fc424e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions DEPRECATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
### DEP0002

`hops-express` is deprecated. The contained feature is now part of the hops package.

### DEP0003

The config property `shouldPrefetchOnServer` is deprecated and will be removed in favor of the property `allowServerSideDataFetching` in the next major release of Hops.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ _Reminder: These settings go into your `package.json` or [Hops configuration fil

| Name | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute route-bound action creators during server-side rendering |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute route-bound action creators during server-side rendering **[deprecated]** |
| `allowServerSideDataFetching` | `Boolean` | `true` | _no_ | Whether Hops is allowed to execute route-bound action creators during server-side rendering |

##### Options

Expand Down
15 changes: 12 additions & 3 deletions packages/redux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ Check out this [integration test](https://github.com/xing/hops/tree/master/packa

| Name | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute route-bound action creators during server-side rendering |
| `shouldPrefetchOnServer` | `Boolean` | `true` | _no_ | Whether Hops should execute route-bound action creators during server-side rendering **[deprecated]** |
| `allowServerSideDataFetching` | `Boolean` | `true` | _no_ | Whether Hops is allowed to execute route-bound action creators during server-side rendering |

##### `shouldPrefetchOnServer`
##### `shouldPrefetchOnServer` [deprecated]

**Note:** This option has been deprecated. See the [DEPRECATIONS document](https://github.com/xing/hops/blob/master/DEPRECATIONS.md#DEP0003) for more informations.

Whether you want "full server-side rendering" or just "app shell" rendering.

Expand All @@ -44,6 +47,12 @@ This option controls whether you want Hops to execute the configured [route-boun
}
```

##### `allowServerSideDataFetching`

If you don't want Hops to execute route-bound action creators during server-side rendering, set this value to `false`.

Bear in mind, that setting this value to `true` on the other hand has no mandatory character. This means that there's no way to force Hops to execute server-side requests. As soon as there's a single Hops preset in place, that either sets the `allowServerSideDataFetching`-value to `false` or implements the [`canPrefetchOnServer`](https://github.com/xing/hops/tree/master/packages/redux#canprefetchonserver-boolean-sequence-server)-hook to return `false`, there won't be any server-side requests.

#### Render Options

This preset has only a single runtime option which can be passed to the `render()` options inside the `redux` key (see example above).
Expand Down Expand Up @@ -153,6 +162,6 @@ const incrementFetch = () => (dispatch, getState, { fetch }) => {

This is a hook that can be used to customize the behavior of when Hops can prefetch data during server-side rendering. E.g. execute route-bound action creators during initial render. If any function of this sequence returns false it prevents server fetching for this request.

By default it returns whatever is configured in the [`shouldPrefetchOnServer` preset option](#shouldprefetchonserver).
By default it returns whatever is configured in the [`allowServerSideDataFetching` preset option](#allowServerSideDataFetching).

In case you need more control over the server-side rendering you can implement this method and provide your own implementation that decides if data should be prefetched during server-side rendering.
15 changes: 13 additions & 2 deletions packages/redux/action-creator-dispatcher/mixin.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
sync: { sequence },
},
} = require('hops-mixin');
const deprecate = require('depd')('hops-redux');

const ReduxActionCreatorCommonMixin = require('./mixin.runtime-common');

Expand All @@ -18,9 +19,19 @@ class ReduxActionCreatorServerMixin extends ReduxActionCreatorCommonMixin {
}

canPrefetchOnServer() {
const { shouldPrefetchOnServer } = this.config;
const { shouldPrefetchOnServer, allowServerSideDataFetching } = this.config;

if (typeof shouldPrefetchOnServer === 'boolean') {
deprecate(
'[DEP0003] The config property "shouldPrefetchOnServer" is deprecated and will' +
' be removed in favor of the property "allowServerSideDataFetching" in the next' +
' major release of Hops.'
);
}

return shouldPrefetchOnServer !== false;
return (
shouldPrefetchOnServer !== false && allowServerSideDataFetching !== false
);
}

async fetchData(data) {
Expand Down
1 change: 1 addition & 0 deletions packages/redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"url": "https://github.com/xing/hops.git"
},
"dependencies": {
"depd": "^2.0.0",
"history": "^4.10.1",
"hops-mixin": "^12.0.0-alpha.3",
"prop-types": "^15.7.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/redux/preset.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require('path');
module.exports = {
mixins: [__dirname, path.join(__dirname, 'action-creator-dispatcher')],
shouldPrefetchOnServer: true,
allowServerSideDataFetching: true,
configSchema: {
shouldPrefetchOnServer: { type: 'boolean' },
allowServerSideDataFetching: { type: 'boolean' },
},
};

0 comments on commit 2fc424e

Please sign in to comment.