mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Canvas] Tear down history instances (#68277)
* [Canvas] Tear down history instances * Always create history on Canvas startup Co-authored-by: Poff Poffenberger <poffdeluxe@gmail.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
0189ae5c3f
commit
16fbbf4345
2 changed files with 22 additions and 11 deletions
|
@ -33,7 +33,7 @@ import { CapabilitiesStrings } from '../i18n';
|
||||||
|
|
||||||
import { startServices, services } from './services';
|
import { startServices, services } from './services';
|
||||||
// @ts-ignore Untyped local
|
// @ts-ignore Untyped local
|
||||||
import { destroyHistory } from './lib/history_provider';
|
import { createHistory, destroyHistory } from './lib/history_provider';
|
||||||
// @ts-ignore Untyped local
|
// @ts-ignore Untyped local
|
||||||
import { stopRouter } from './lib/router_provider';
|
import { stopRouter } from './lib/router_provider';
|
||||||
import { initFunctions } from './functions';
|
import { initFunctions } from './functions';
|
||||||
|
@ -97,6 +97,9 @@ export const initializeCanvas = async (
|
||||||
services.expressions.getService().registerFunction(fn);
|
services.expressions.getService().registerFunction(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-initialize our history
|
||||||
|
createHistory();
|
||||||
|
|
||||||
// Create Store
|
// Create Store
|
||||||
const canvasStore = await createStore(coreSetup, setupPlugins);
|
const canvasStore = await createStore(coreSetup, setupPlugins);
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ function wrapHistoryInstance(history) {
|
||||||
return wrappedHistory;
|
return wrappedHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
let instances = new WeakMap();
|
const instances = new WeakMap();
|
||||||
|
|
||||||
const getHistoryInstance = (win) => {
|
const getHistoryInstance = (win) => {
|
||||||
// if no window object, use memory module
|
// if no window object, use memory module
|
||||||
|
@ -144,13 +144,7 @@ const getHistoryInstance = (win) => {
|
||||||
return createHashStateHistory();
|
return createHashStateHistory();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const historyProvider = (win = getWindow()) => {
|
export const createHistory = (win = getWindow()) => {
|
||||||
// return cached instance if one exists
|
|
||||||
const instance = instances.get(win);
|
|
||||||
if (instance) {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create and cache wrapped history instance
|
// create and cache wrapped history instance
|
||||||
const historyInstance = getHistoryInstance(win);
|
const historyInstance = getHistoryInstance(win);
|
||||||
const wrappedInstance = wrapHistoryInstance(historyInstance);
|
const wrappedInstance = wrapHistoryInstance(historyInstance);
|
||||||
|
@ -159,6 +153,20 @@ export const historyProvider = (win = getWindow()) => {
|
||||||
return wrappedInstance;
|
return wrappedInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const destroyHistory = () => {
|
export const historyProvider = (win = getWindow()) => {
|
||||||
instances = new WeakMap();
|
// return cached instance if one exists
|
||||||
|
const instance = instances.get(win);
|
||||||
|
if (instance) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return createHistory(win);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const destroyHistory = (win = getWindow()) => {
|
||||||
|
const instance = instances.get(win);
|
||||||
|
|
||||||
|
if (instance) {
|
||||||
|
instance.resetOnChange();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue