Skip to content

Commit 1f23166

Browse files
committed
batch api controller
1 parent 27a427e commit 1f23166

File tree

1 file changed

+60
-51
lines changed

1 file changed

+60
-51
lines changed

dash/dash-renderer/src/APIController.react.js

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {connect} from 'react-redux';
1+
import {batch, connect} from 'react-redux';
22
import {includes, isEmpty} from 'ramda';
33
import React, {useEffect, useRef, useState, createContext} from 'react';
44
import PropTypes from 'prop-types';
@@ -136,64 +136,73 @@ function storeEffect(props, events, setErrorLoading) {
136136
layoutRequest
137137
} = props;
138138

139-
if (isEmpty(layoutRequest)) {
140-
if (typeof hooks.layout_pre === 'function') {
141-
hooks.layout_pre();
142-
}
143-
dispatch(apiThunk('_dash-layout', 'GET', 'layoutRequest'));
144-
} else if (layoutRequest.status === STATUS.OK) {
145-
if (isEmpty(layout)) {
146-
if (typeof hooks.layout_post === 'function') {
147-
hooks.layout_post(layoutRequest.content);
139+
batch(() => {
140+
if (isEmpty(layoutRequest)) {
141+
if (typeof hooks.layout_pre === 'function') {
142+
hooks.layout_pre();
143+
}
144+
dispatch(apiThunk('_dash-layout', 'GET', 'layoutRequest'));
145+
} else if (layoutRequest.status === STATUS.OK) {
146+
if (isEmpty(layout)) {
147+
if (typeof hooks.layout_post === 'function') {
148+
hooks.layout_post(layoutRequest.content);
149+
}
150+
const finalLayout = applyPersistence(
151+
layoutRequest.content,
152+
dispatch
153+
);
154+
dispatch(
155+
setPaths(
156+
computePaths(finalLayout, [], null, events.current)
157+
)
158+
);
159+
dispatch(setLayout(finalLayout));
148160
}
149-
const finalLayout = applyPersistence(
150-
layoutRequest.content,
151-
dispatch
161+
}
162+
163+
if (isEmpty(dependenciesRequest)) {
164+
dispatch(
165+
apiThunk('_dash-dependencies', 'GET', 'dependenciesRequest')
152166
);
167+
} else if (
168+
dependenciesRequest.status === STATUS.OK &&
169+
isEmpty(graphs)
170+
) {
153171
dispatch(
154-
setPaths(computePaths(finalLayout, [], null, events.current))
172+
setGraphs(
173+
computeGraphs(
174+
dependenciesRequest.content,
175+
dispatchError(dispatch)
176+
)
177+
)
155178
);
156-
dispatch(setLayout(finalLayout));
157179
}
158-
}
159180

160-
if (isEmpty(dependenciesRequest)) {
161-
dispatch(apiThunk('_dash-dependencies', 'GET', 'dependenciesRequest'));
162-
} else if (dependenciesRequest.status === STATUS.OK && isEmpty(graphs)) {
163-
dispatch(
164-
setGraphs(
165-
computeGraphs(
166-
dependenciesRequest.content,
167-
dispatchError(dispatch)
168-
)
169-
)
170-
);
171-
}
172-
173-
if (
174-
// dependenciesRequest and its computed stores
175-
dependenciesRequest.status === STATUS.OK &&
176-
!isEmpty(graphs) &&
177-
// LayoutRequest and its computed stores
178-
layoutRequest.status === STATUS.OK &&
179-
!isEmpty(layout) &&
180-
// Hasn't already hydrated
181-
appLifecycle === getAppState('STARTED')
182-
) {
183-
let hasError = false;
184-
try {
185-
dispatch(hydrateInitialOutputs(dispatchError(dispatch)));
186-
} catch (err) {
187-
// Display this error in devtools, unless we have errors
188-
// already, in which case we assume this new one is moot
189-
if (!error.frontEnd.length && !error.backEnd.length) {
190-
dispatch(onError({type: 'backEnd', error: err}));
181+
if (
182+
// dependenciesRequest and its computed stores
183+
dependenciesRequest.status === STATUS.OK &&
184+
!isEmpty(graphs) &&
185+
// LayoutRequest and its computed stores
186+
layoutRequest.status === STATUS.OK &&
187+
!isEmpty(layout) &&
188+
// Hasn't already hydrated
189+
appLifecycle === getAppState('STARTED')
190+
) {
191+
let hasError = false;
192+
try {
193+
dispatch(hydrateInitialOutputs(dispatchError(dispatch)));
194+
} catch (err) {
195+
// Display this error in devtools, unless we have errors
196+
// already, in which case we assume this new one is moot
197+
if (!error.frontEnd.length && !error.backEnd.length) {
198+
dispatch(onError({type: 'backEnd', error: err}));
199+
}
200+
hasError = true;
201+
} finally {
202+
setErrorLoading(hasError);
191203
}
192-
hasError = true;
193-
} finally {
194-
setErrorLoading(hasError);
195204
}
196-
}
205+
});
197206
}
198207

199208
UnconnectedContainer.propTypes = {

0 commit comments

Comments
 (0)