Skip to content

Commit c6c6ab6

Browse files
authored
Merge pull request #1815 from plotly/embedded-app-switching
callback_resolved hook, added DESTROYED app state
2 parents 2c456cd + d46bec5 commit c6c6ab6

File tree

7 files changed

+27
-4
lines changed

7 files changed

+27
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ function storeEffect(props, events, setErrorLoading) {
184184
UnconnectedContainer.propTypes = {
185185
appLifecycle: PropTypes.oneOf([
186186
getAppState('STARTED'),
187-
getAppState('HYDRATED')
187+
getAppState('HYDRATED'),
188+
getAppState('DESTROYED')
188189
]),
189190
dispatch: PropTypes.func,
190191
dependenciesRequest: PropTypes.object,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class UnconnectedAppContainer extends React.Component {
1414
if (
1515
props.hooks.request_pre !== null ||
1616
props.hooks.request_post !== null ||
17+
props.hooks.callback_resolved !== null ||
1718
props.hooks.request_refresh_jwt !== null
1819
) {
1920
let hooks = props.hooks;

dash/dash-renderer/src/AppProvider.react.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ AppProvider.propTypes = {
1919
hooks: PropTypes.shape({
2020
request_pre: PropTypes.func,
2121
request_post: PropTypes.func,
22+
callback_resolved: PropTypes.func,
2223
request_refresh_jwt: PropTypes.func
2324
})
2425
};
@@ -27,6 +28,7 @@ AppProvider.defaultProps = {
2728
hooks: {
2829
request_pre: null,
2930
request_post: null,
31+
callback_resolved: null,
3032
request_refresh_jwt: null
3133
}
3234
};

dash/dash-renderer/src/observers/executingCallbacks.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010

1111
import {IStoreObserverDefinition} from '../StoreObserver';
1212
import {IStoreState} from '../store';
13+
import {getAppState} from '../reducers/constants';
1314

1415
const observer: IStoreObserverDefinition<IStoreState> = {
1516
observer: ({dispatch, getState}) => {
@@ -44,9 +45,19 @@ const observer: IStoreObserverDefinition<IStoreState> = {
4445
const result = await cb.executionPromise;
4546

4647
const {
47-
callbacks: {watched}
48+
callbacks: {watched},
49+
appLifecycle,
50+
hooks: {callback_resolved}
4851
} = getState();
4952

53+
if (appLifecycle !== getAppState('HYDRATED')) {
54+
return;
55+
}
56+
57+
if (callback_resolved) {
58+
callback_resolved(cb.callback, result);
59+
}
60+
5061
// Check if it's been removed from the `watched` list since - on callback completion, another callback may be cancelled
5162
// Find the callback instance or one that matches its promise (eg. could have been pruned)
5263
const currentCb = find(

dash/dash-renderer/src/observers/prioritizedCallbacks.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
IPrioritizedCallback
2525
} from '../types/callbacks';
2626
import {IStoreObserverDefinition} from '../StoreObserver';
27+
import {getAppState} from '../reducers/constants';
2728

2829
const sortPriority = (c1: ICallback, c2: ICallback): number => {
2930
return (c1.priority ?? '') > (c2.priority ?? '') ? -1 : 1;
@@ -67,12 +68,17 @@ const observer: IStoreObserverDefinition<IStoreState> = {
6768
config,
6869
hooks,
6970
layout,
70-
paths
71+
paths,
72+
appLifecycle
7173
} = getState();
7274
let {
7375
callbacks: {prioritized}
7476
} = getState();
7577

78+
if (appLifecycle !== getAppState('HYDRATED')) {
79+
return;
80+
}
81+
7682
const available = Math.max(0, 12 - executing.length - watched.length);
7783

7884
// Order prioritized callbacks based on depth and breadth of callback chain

dash/dash-renderer/src/reducers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export function getAppState(state) {
22
const stateList = {
33
STARTED: 'STARTED',
4-
HYDRATED: 'HYDRATED'
4+
HYDRATED: 'HYDRATED',
5+
DESTROYED: 'DESTROYED'
56
};
67
if (stateList[state]) {
78
return stateList[state];

dash/dash-renderer/src/reducers/hooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const customHooks = (
22
state = {
33
request_pre: null,
44
request_post: null,
5+
callback_resolved: null,
56
request_refresh_jwt: null,
67
bear: false
78
},

0 commit comments

Comments
 (0)