From 518f9c58465a4f207910c5a9c890f86f37e175cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20=C3=85kerstrand?= Date: Tue, 11 Oct 2016 09:31:53 +0200 Subject: [PATCH] Setting for `forceRefresh` (#36) * Allows setting `forceRefresh`-option to `browserHistory` through Roc settings * Fixes ESLint mistake --- .../roc-package-web-app-react/app/client/create-client.js | 4 ++++ .../roc-package-web-app-react/src/config/roc.config.js | 3 +++ .../src/config/roc.config.meta.js | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/extensions/roc-package-web-app-react/app/client/create-client.js b/extensions/roc-package-web-app-react/app/client/create-client.js index ad8d67a..12a039e 100644 --- a/extensions/roc-package-web-app-react/app/client/create-client.js +++ b/extensions/roc-package-web-app-react/app/client/create-client.js @@ -75,8 +75,12 @@ export default function createClient({ createRoutes, createStore, mountNode }) { const render = () => { const node = document.getElementById(mountNode); + const forceRefreshSetting = rocConfig.runtime.history.forceRefresh; let history = useRouterHistory(createHistory)({ basename, + forceRefresh: typeof forceRefreshSetting === 'function' + ? forceRefreshSetting() + : forceRefreshSetting, }); let initialLoading = null; diff --git a/extensions/roc-package-web-app-react/src/config/roc.config.js b/extensions/roc-package-web-app-react/src/config/roc.config.js index 88775b8..23e7057 100644 --- a/extensions/roc-package-web-app-react/src/config/roc.config.js +++ b/extensions/roc-package-web-app-react/src/config/roc.config.js @@ -31,6 +31,9 @@ export default { debug: { client: 'roc:*', }, + history: { + forceRefresh: undefined, + }, configWhitelistProperty: 'DANGEROUSLY_EXPOSE_TO_CLIENT', fetch: { server: ['fetch'], diff --git a/extensions/roc-package-web-app-react/src/config/roc.config.meta.js b/extensions/roc-package-web-app-react/src/config/roc.config.meta.js index a695647..fe5c27f 100644 --- a/extensions/roc-package-web-app-react/src/config/roc.config.meta.js +++ b/extensions/roc-package-web-app-react/src/config/roc.config.meta.js @@ -1,4 +1,4 @@ -import { isString, isBoolean, isPath, isArray, isObject, notEmpty, required } from 'roc/validators'; +import { isString, isBoolean, isPath, isArray, isObject, notEmpty, required, oneOf, isFunction } from 'roc/validators'; export default { settings: { @@ -103,6 +103,12 @@ export default { }, }, }, + history: { + forceRefresh: { + description: 'Whether to force load from server rather than do single page navigation', + validator: oneOf(isBoolean, isFunction), + }, + }, }, }, };