If we are not in iFrame just use localStorage

This commit is contained in:
Chi Vinh Le
2018-02-01 13:53:15 +01:00
parent 2e59f64738
commit dc5a3e43a6
2 changed files with 17 additions and 11 deletions
+1 -9
View File
@@ -14,16 +14,8 @@ import reducers from './reducers';
import TalkProvider from 'coral-framework/components/TalkProvider';
import pluginsConfig from 'pluginsConfig';
function inIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
// TODO: move init code into `bootstrap` service after auth has been refactored.
function preInit({ store, pym }) {
function preInit({ store, pym, inIframe }) {
// TODO: This is popup specific code and needs to be refactored.
if (!inIframe()) {
store.dispatch(addExternalConfig({}));
+16 -2
View File
@@ -43,6 +43,14 @@ const getAuthToken = (store, storage) => {
return null;
};
function areWeInIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
/**
* createContext setups and returns Talk dependencies that should be
* passed to `TalkProvider`.
@@ -63,11 +71,16 @@ export async function createContext({
preInit,
init = noop,
} = {}) {
const inIframe = areWeInIframe();
const eventEmitter = new EventEmitter({ wildcard: true });
const localStorage = createStorage('localStorage');
const sessionStorage = createStorage('sessionStorage');
const pymLocalStorage = createPymStorage(pym, 'localStorage');
const pymSessionStorage = createPymStorage(pym, 'sessionStorage');
const pymLocalStorage = inIframe
? createPymStorage(pym, 'localStorage')
: localStorage;
const pymSessionStorage = inIframe
? createPymStorage(pym, 'sessionStorage')
: localStorage;
const history = createHistory(BASE_PATH);
const introspection = createIntrospection(introspectionData);
let store = null;
@@ -124,6 +137,7 @@ export async function createContext({
introspection,
pymLocalStorage,
pymSessionStorage,
inIframe,
};
// Load framework fragments.