[Maps] make getStore syncrouns (#29895)

This commit is contained in:
Nathan Reese 2019-02-03 20:38:17 -07:00 committed by GitHub
parent bc5d5143d4
commit 8d150e7379
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 29 deletions

View file

@ -97,35 +97,23 @@ app.controller('GisMapController', ($scope, $route, config, kbnUrl, localStorage
$scope.updateQueryAndDispatch = function ({ dateRange, query }) {
$scope.query = query;
$scope.time = dateRange;
getStore().then(store => {
// ignore outdated query
if ($scope.query !== query && $scope.time !== dateRange) {
return;
}
syncAppAndGlobalState();
store.dispatch(setQuery({ query: $scope.query, timeFilters: $scope.time }));
syncAppAndGlobalState();
});
getStore().dispatch(setQuery({ query: $scope.query, timeFilters: $scope.time }));
};
$scope.onRefreshChange = function ({ isPaused, refreshInterval }) {
$scope.refreshConfig = {
isPaused,
interval: refreshInterval ? refreshInterval : $scope.refreshConfig.interval
};
getStore().then(store => {
// ignore outdated
if ($scope.refreshConfig.isPaused !== isPaused && $scope.refreshConfig.interval !== refreshInterval) {
return;
}
syncAppAndGlobalState();
store.dispatch(setRefreshConfig($scope.refreshConfig));
syncAppAndGlobalState();
});
getStore().dispatch(setRefreshConfig($scope.refreshConfig));
};
getStore().then(store => {
function renderMap() {
const store = getStore();
// clear old UI state
store.dispatch(setSelectedLayer(null));
store.dispatch(updateFlyout(FLYOUT_STATE.NONE));
@ -158,8 +146,10 @@ app.controller('GisMapController', ($scope, $route, config, kbnUrl, localStorage
<GisMap/>
</I18nProvider>
</Provider>,
root);
});
root
);
}
renderMap();
let prevIndexPatternIds;
async function updateIndexPatterns(nextIndexPatternIds) {
@ -220,8 +210,7 @@ app.controller('GisMapController', ($scope, $route, config, kbnUrl, localStorage
config.watch('k7design', (val) => $scope.showPluginBreadcrumbs = !val);
async function doSave(saveOptions) {
const store = await getStore();
savedMap.syncWithStore(store.getState());
savedMap.syncWithStore(getStore().getState());
let id;
try {

View file

@ -14,7 +14,7 @@ import { VectorStyle } from './styles/vector_style';
import { LeftInnerJoin } from './joins/left_inner_join';
import { FeatureTooltip } from '../../components/map/feature_tooltip';
import { store } from '../../store/store';
import { getStore } from '../../store/store';
import { getMapColors } from '../../selectors/map_selectors';
import _ from 'lodash';
@ -40,8 +40,7 @@ export class VectorLayer extends AbstractLayer {
layerDescriptor.type = VectorLayer.type;
if (!options.style) {
// TODO pass store in as argument. Accessing store this way is unsafe
const mapColors = getMapColors(store.getState());
const mapColors = getMapColors(getStore().getState());
const styleProperties = VectorStyle.createDefaultStyleProperties(mapColors);
layerDescriptor.style = VectorStyle.createDescriptor(styleProperties);
}

View file

@ -9,8 +9,7 @@ import thunk from 'redux-thunk';
import ui from './ui';
import { map } from './map';
// TODO this should not be exported and all access to the store be via getStore
export let store;
let store;
const rootReducer = combineReducers({
map,
@ -21,7 +20,7 @@ const enhancers = [ applyMiddleware(thunk) ];
window.__REDUX_DEVTOOLS_EXTENSION
&& enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__());
export const getStore = async function () {
export const getStore = function () {
if (store) {
return store;
}