Save static config to redux

This commit is contained in:
Chi Vinh Le
2018-02-07 21:08:37 +01:00
parent ffbcd93c3f
commit bad0363628
5 changed files with 38 additions and 3 deletions
+6
View File
@@ -0,0 +1,6 @@
import * as actions from '../constants/static';
export const setStaticConfiguration = config => ({
type: actions.SET_STATIC_CONFIGURATION,
config,
});
@@ -0,0 +1,3 @@
const prefix = `TALK_FRAMEWORK`;
export const SET_STATIC_CONFIGURATION = `${prefix}_SET_STATIC_CONFIGURATION`;
+7
View File
@@ -0,0 +1,7 @@
import auth from './auth';
import staticConfiguration from './static';
export default {
auth,
static: staticConfiguration,
};
+15
View File
@@ -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;
}
}
+7 -3
View File
@@ -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.