Skip to content

Test nested connections and add nested connection #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/containers/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export default class Section extends Component {
} else if (isAttr) {
if (child.type.supplyPlotProps) {
plotProps = child.type.supplyPlotProps(child.props, context);
if (child.type.modifyPlotProps) {
child.type.modifyPlotProps(child.props, context, plotProps);
}
} else {
plotProps = unpackPlotProps(child.props, context);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see a use for this unpack, then wouldn't the if (child.type.modifyPlotProps) block possibly be relevant in that case too? ie should it be moved outside that if/else block, so the existences of supply and modify are independent?

}
Expand Down
7 changes: 3 additions & 4 deletions src/components/fields/AxesRange.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Numeric from './Numeric';
import {connectToContainer, unpackPlotProps} from '../../lib';
import {connectToContainer} from '../../lib';

function supplyPlotProps(props, context) {
const plotProps = unpackPlotProps(props, context);
function modifyPlotProps(props, context, plotProps) {
const {fullContainer} = plotProps;
if (plotProps.isVisible && fullContainer && fullContainer.autorange) {
plotProps.isVisible = false;
}
return plotProps;
}

export default connectToContainer(Numeric, {supplyPlotProps});
export default connectToContainer(Numeric, {modifyPlotProps});
8 changes: 3 additions & 5 deletions src/components/fields/CanvasSize.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import Numeric from './Numeric';
import {connectToContainer, unpackPlotProps} from '../../lib';
import {connectToContainer} from '../../lib';

function supplyPlotProps(props, context) {
const plotProps = unpackPlotProps(props, context);
function modifyPlotProps(props, context, plotProps) {
const {fullContainer} = plotProps;
if (plotProps.isVisible && fullContainer && fullContainer.autosize) {
plotProps.isVisible = false;
}
return plotProps;
}

export default connectToContainer(Numeric, {supplyPlotProps});
export default connectToContainer(Numeric, {modifyPlotProps});
6 changes: 2 additions & 4 deletions src/components/fields/DataSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ DataSelector.propTypes = {
...Field.propTypes,
};

function supplyPlotProps(props, context) {
const plotProps = unpackPlotProps(props, context);
function modifyPlotProps(props, context, plotProps) {
if (attributeIsData(plotProps.attrMeta)) {
plotProps.isVisible = true;
}
return plotProps;
}

export default connectToContainer(DataSelector, {supplyPlotProps});
export default connectToContainer(DataSelector, {modifyPlotProps});
2 changes: 1 addition & 1 deletion src/lib/__tests__/nestedContainerConnections-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Plot Connection', () => {
const DeeplyConnectedNumeric = connectTraceToPlot(
connectLayoutToPlot(
connectToContainer(Numeric, {
supplyPlotProps: (props, context, plotProps) => {
modifyPlotProps: (props, context, plotProps) => {
plotProps.connectToContainerModifiedPlotProp = true;
},
})
Expand Down
6 changes: 6 additions & 0 deletions src/lib/connectLayoutToPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default function connectLayoutToPlot(WrappedComponent) {
return unpackPlotProps(props, context);
}

static modifyPlotProps(props, context, plotProps) {
if (WrappedComponent.modifyPlotProps) {
WrappedComponent.modifyPlotProps(props, context, plotProps);
}
}

getChildContext() {
return getLayoutContext(this.context);
}
Expand Down
18 changes: 18 additions & 0 deletions src/lib/connectToContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const containerConnectedContextTypes = {

export default function connectToContainer(WrappedComponent, config = {}) {
class ContainerConnectedComponent extends Component {
// The most recent supplyPlotProps is used to supply the initial plotProps.
// This means any config routines are run before the inner components.
static supplyPlotProps(props, context) {
if (config.supplyPlotProps) {
return config.supplyPlotProps(props, context);
Expand All @@ -28,6 +30,17 @@ export default function connectToContainer(WrappedComponent, config = {}) {
return unpackPlotProps(props, context);
}

// Run the inner modifications first and allow more recent modifyPlotProp
// config function to modify last.
static modifyPlotProps(props, context, plotProps) {
if (WrappedComponent.modifyPlotProps) {
WrappedComponent.modifyPlotProps(props, context, plotProps);
}
if (config.modifyPlotProps) {
config.modifyPlotProps(props, context, plotProps);
}
}

constructor(props, context) {
super(props, context);

Expand All @@ -50,6 +63,11 @@ export default function connectToContainer(WrappedComponent, config = {}) {
props,
context
);
ContainerConnectedComponent.modifyPlotProps(
props,
context,
this.plotProps
);
}
}

Expand Down