Skip to content

Commit 5035be2

Browse files
committed
delete redundancy in pattern-matching callback resolution
1 parent 9acc204 commit 5035be2

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

dash/dash-renderer/src/actions/dependencies.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,15 +1036,19 @@ function getCallbackByOutput(graphs, paths, id, prop) {
10361036
function addResolvedFromOutputs(callback, outPattern, outs, matches) {
10371037
const out0Keys = Object.keys(outPattern.id).sort();
10381038
const out0PatternVals = props(out0Keys, outPattern.id);
1039+
const foundCbIds = {};
10391040
outs.forEach(({id: outId}) => {
10401041
const outVals = props(out0Keys, outId);
1041-
matches.push(
1042-
makeResolvedCallback(
1043-
callback,
1044-
resolveDeps(out0Keys, outVals, out0PatternVals),
1045-
getAnyVals(out0PatternVals, outVals)
1046-
)
1042+
const resolved = makeResolvedCallback(
1043+
callback,
1044+
resolveDeps(out0Keys, outVals, out0PatternVals),
1045+
getAnyVals(out0PatternVals, outVals)
10471046
);
1047+
const {resolvedId} = resolved;
1048+
if (!foundCbIds[resolvedId]) {
1049+
matches.push(resolved);
1050+
foundCbIds[resolvedId] = true;
1051+
}
10481052
});
10491053
}
10501054

dash/dash-renderer/src/actions/dependencies_ts.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,23 @@ export function getPriority(
102102
callback: ICallback
103103
): string {
104104
let callbacks: ICallback[] = [callback];
105-
let touchedOutputs: {[key: string]: boolean} = {};
105+
const touchedOutputs: {[key: string]: boolean} = {};
106+
const touchedCbIds: {[key: string]: boolean} = {};
106107
const priority: number[] = [];
107108

108109
while (callbacks.length) {
110+
callbacks = filter(c => {
111+
const touched = touchedCbIds[c.resolvedId];
112+
touchedCbIds[c.resolvedId] = true;
113+
return touched;
114+
}, callbacks);
115+
109116
const outputs = filter(
110117
o => !touchedOutputs[combineIdAndProp(o)],
111118
flatten(map(cb => flatten(cb.getOutputs(paths)), callbacks))
112119
);
113120

114-
touchedOutputs = reduce(
115-
(touched, o) => assoc(combineIdAndProp(o), true, touched),
116-
touchedOutputs,
117-
outputs
118-
);
121+
outputs.forEach(o => (touchedOutputs[combineIdAndProp(o)] = true));
119122

120123
callbacks = flatten(
121124
map(

0 commit comments

Comments
 (0)