mirror of
https://github.com/wassname/talk.git
synced 2026-07-11 09:51:37 +08:00
If we are not in iFrame just use localStorage
This commit is contained in:
@@ -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
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user