From bad036362868adefea89b00275225aa220c58cb2 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Wed, 7 Feb 2018 21:08:37 +0100 Subject: [PATCH] Save static config to redux --- client/coral-framework/actions/static.js | 6 ++++++ client/coral-framework/constants/static.js | 3 +++ client/coral-framework/reducers/index.js | 7 +++++++ client/coral-framework/reducers/static.js | 15 +++++++++++++++ client/coral-framework/services/bootstrap.js | 10 +++++++--- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 client/coral-framework/actions/static.js create mode 100644 client/coral-framework/constants/static.js create mode 100644 client/coral-framework/reducers/index.js create mode 100644 client/coral-framework/reducers/static.js diff --git a/client/coral-framework/actions/static.js b/client/coral-framework/actions/static.js new file mode 100644 index 000000000..fd28ad39d --- /dev/null +++ b/client/coral-framework/actions/static.js @@ -0,0 +1,6 @@ +import * as actions from '../constants/static'; + +export const setStaticConfiguration = config => ({ + type: actions.SET_STATIC_CONFIGURATION, + config, +}); diff --git a/client/coral-framework/constants/static.js b/client/coral-framework/constants/static.js new file mode 100644 index 000000000..5f3804662 --- /dev/null +++ b/client/coral-framework/constants/static.js @@ -0,0 +1,3 @@ +const prefix = `TALK_FRAMEWORK`; + +export const SET_STATIC_CONFIGURATION = `${prefix}_SET_STATIC_CONFIGURATION`; diff --git a/client/coral-framework/reducers/index.js b/client/coral-framework/reducers/index.js new file mode 100644 index 000000000..d54932b9b --- /dev/null +++ b/client/coral-framework/reducers/index.js @@ -0,0 +1,7 @@ +import auth from './auth'; +import staticConfiguration from './static'; + +export default { + auth, + static: staticConfiguration, +}; diff --git a/client/coral-framework/reducers/static.js b/client/coral-framework/reducers/static.js new file mode 100644 index 000000000..c8bc1afc2 --- /dev/null +++ b/client/coral-framework/reducers/static.js @@ -0,0 +1,15 @@ +import * as actions from '../constants/static'; + +const initialState = {}; + +export default function auth(state = initialState, action) { + switch (action.type) { + case actions.SET_STATIC_CONFIGURATION: + return { + ...state, + ...action.config, + }; + default: + return state; + } +} diff --git a/client/coral-framework/services/bootstrap.js b/client/coral-framework/services/bootstrap.js index f0ab7c41f..9b5982edc 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -22,8 +22,9 @@ import { import { createHistory } from 'coral-framework/services/history'; import { createIntrospection } from 'coral-framework/services/introspection'; import introspectionData from 'coral-framework/graphql/introspection.json'; -import auth from '../reducers/auth'; +import coreReducers from '../reducers'; import { checkLogin } from '../actions/auth'; +import { setStaticConfiguration } from '../actions/static'; /** * getAuthToken returns the active auth token or null @@ -100,7 +101,8 @@ export async function createContext({ token, }); - let { LIVE_URI: liveUri } = getStaticConfiguration(); + const staticConfig = getStaticConfiguration(); + let { LIVE_URI: liveUri } = staticConfig; if (liveUri == null) { // The protocol must match the origin protocol, secure/insecure. const protocol = location.protocol === 'https:' ? 'wss' : 'ws'; @@ -163,7 +165,8 @@ export async function createContext({ // Create our redux store. const finalReducers = { - authCore: auth, + authCore: coreReducers.auth, + static: coreReducers.static, ...reducers, ...plugins.getReducers(), }; @@ -183,6 +186,7 @@ export async function createContext({ [client.middleware(), apolloErrorReporter, createReduxEmitter(eventEmitter)] ); + store.dispatch(setStaticConfiguration(staticConfig)); store.dispatch(checkLogin()); // Run pre initialization.