Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 888b5a0

Browse files
committed
Non breaking multi-output.
1 parent 28a83f2 commit 888b5a0

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

src/actions/index.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,28 @@ function updateOutput(
397397
* }
398398
*
399399
*/
400+
401+
const [outputComponentId, outputProp] = outputIdAndProp.split('.');
400402
const payload = {
401-
output: outputIdAndProp,
403+
output: config.multi_output ? outputIdAndProp :
404+
{
405+
id: outputComponentId,
406+
property: outputProp
407+
}
402408
};
403409

404410
if (event) {
405411
payload.event = event;
406412
}
407413

408414
const {inputs, state} = dependenciesRequest.content.find(
409-
dependency => dependency.output === outputIdAndProp
415+
dependency => {
416+
if (config.multi_output) {
417+
return dependency.output === outputIdAndProp
418+
}
419+
return dependency.output.id === outputComponentId &&
420+
dependency.output.property === outputProp
421+
}
410422
);
411423
const validKeys = keys(paths);
412424
if (inputs.length > 0) {
@@ -566,18 +578,21 @@ function updateOutput(
566578
*/
567579

568580
const {paths} = getState();
581+
const multi = data.multi;
569582

570-
Object.entries(data.response).forEach(([outputIdAndProp, props]) => {
583+
const handleResponse = ([outputIdAndProp, props]) => {
584+
// Backward compatibility
585+
const pathKey = multi ? outputIdAndProp : outputComponentId;
571586
const observerUpdatePayload = {
572-
itempath: paths[outputIdAndProp],
587+
itempath: paths[pathKey],
573588
props,
574589
source: 'response'
575590
};
576591
dispatch(updateProps(observerUpdatePayload));
577592

578593
dispatch(
579594
notifyObservers({
580-
id: outputIdAndProp,
595+
id: pathKey,
581596
props: props,
582597
})
583598
);
@@ -592,7 +607,7 @@ function updateOutput(
592607
computePaths({
593608
subTree: observerUpdatePayload.props.children,
594609
startingPath: concat(
595-
paths[outputIdAndProp],
610+
paths[pathKey],
596611
['props', 'children']
597612
),
598613
})
@@ -735,7 +750,15 @@ function updateOutput(
735750
});
736751
}
737752
}
738-
});
753+
};
754+
if (multi) {
755+
Object.entries(data.response).forEach(handleResponse)
756+
} else {
757+
handleResponse([
758+
outputIdAndProp,
759+
data.response.props
760+
])
761+
}
739762
});
740763
});
741764
}

src/reducers/dependencyGraph.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {type} from 'ramda';
12
import {DepGraph} from 'dependency-graph';
23

34
const initialGraph = {};
@@ -11,17 +12,23 @@ const graphs = (state = initialGraph, action) => {
1112

1213
dependencies.forEach(function registerDependency(dependency) {
1314
const {output, inputs, events} = dependency;
15+
16+
// Multi output supported will be a string already
17+
// Backward compatibility by detecting object.
18+
const outputId = type(output) === 'Object' ?
19+
`${output.id}.${output.property}` : output;
20+
1421
inputs.forEach(inputObject => {
1522
const inputId = `${inputObject.id}.${inputObject.property}`;
16-
inputGraph.addNode(output);
23+
inputGraph.addNode(outputId);
1724
inputGraph.addNode(inputId);
18-
inputGraph.addDependency(inputId, output);
25+
inputGraph.addDependency(inputId, outputId);
1926
});
2027
events.forEach(eventObject => {
2128
const eventId = `${eventObject.id}.${eventObject.event}`;
22-
eventGraph.addNode(output);
29+
eventGraph.addNode(outputId);
2330
eventGraph.addNode(eventId);
24-
eventGraph.addDependency(eventId, output);
31+
eventGraph.addDependency(eventId, outputId);
2532
});
2633
});
2734

0 commit comments

Comments
 (0)