Skip to content

Commit e7df0f8

Browse files
chriddypAkronix
authored andcommitted
fix plotly#44
1 parent 5ce8204 commit e7df0f8

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

src/actions/index.js

+65-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
__,
44
adjust,
55
any,
6+
append,
67
concat,
78
contains,
89
findIndex,
@@ -43,7 +44,6 @@ export function hydrateInitialOutputs() {
4344
}
4445
}
4546

46-
4747
function triggerDefaultState(dispatch, getState) {
4848
const {graphs} = getState();
4949
const {InputGraph} = graphs;
@@ -583,7 +583,49 @@ function updateOutput(
583583
* Organize props by shared outputs so that we
584584
* only make one request per output component
585585
* (even if there are multiple inputs).
586+
*
587+
* For example, we might render 10 inputs that control
588+
* a single output. If that is the case, we only want
589+
* to make a single call, not 10 calls.
590+
*/
591+
592+
/*
593+
* In some cases, the new item will be an output
594+
* with its inputs already rendered (not rendered)
595+
* as part of this update.
596+
* For example, a tab with global controls that
597+
* renders different content containers without any
598+
* additional inputs.
599+
*
600+
* In that case, we'll call `updateOutput` with that output
601+
* and just "pretend" that one if its inputs changed.
602+
*
603+
* If we ever add logic that informs the user on
604+
* "which input changed", we'll have to account for this
605+
* special case (no input changed?)
586606
*/
607+
608+
609+
const outputIds = [];
610+
keys(newProps).forEach(idAndProp => {
611+
if (
612+
// It's an output
613+
InputGraph.dependenciesOf(idAndProp).length === 0 &&
614+
/*
615+
* And none of its inputs are generated in this
616+
* request
617+
*/
618+
intersection(
619+
InputGraph.dependantsOf(idAndProp),
620+
keys(newProps)
621+
).length == 0
622+
) {
623+
outputIds.push(idAndProp);
624+
delete newProps[idAndProp];
625+
}
626+
});
627+
628+
// Dispatch updates to inputs
587629
const reducedNodeIds = reduceInputIds(
588630
keys(newProps), InputGraph);
589631
const depOrder = InputGraph.overallOrder();
@@ -594,6 +636,28 @@ function updateOutput(
594636
sortedNewProps.forEach(function(nodeId) {
595637
dispatch(notifyObservers(newProps[nodeId]));
596638
});
639+
640+
// Dispatch updates to lone outputs
641+
outputIds.forEach(idAndProp => {
642+
const requestUid = uid();
643+
dispatch(setRequestQueue(
644+
append({
645+
controllerId: null, // ??
646+
status: 'loading',
647+
uid: requestUid,
648+
requestTime: Date.now()
649+
}, getState().requestQueue)
650+
));
651+
updateOutput(
652+
idAndProp.split('.')[0],
653+
idAndProp.split('.')[1],
654+
null,
655+
getState,
656+
requestUid,
657+
dispatch
658+
);
659+
})
660+
597661
}
598662

599663

0 commit comments

Comments
 (0)