Skip to content

Commit

Permalink
Separated common elementsof pv props and redistributed later
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGuiteDiamond committed Jan 29, 2020
1 parent 9488a2c commit e25a569
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/ui/widgets/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MacrosProp,
MacrosPropOpt
} from "./propTypes";
import { VType } from "../../types/vtypes/vtypes";

// Useful types for components which will later be turned into widgets
// Required to define stateless component
Expand Down Expand Up @@ -122,29 +123,39 @@ const recursiveWrapping = (
containerStyling: object,
widgetStyling: WidgetStyling | null,
containerProps: object,
widgetProps: object
widgetProps: object,
pvProps?: {
pvName: string;
connected: boolean;
readonly: boolean;
value?: VType;
}
): JSX.Element => {
const [Component, ...remainingComponents] = components;
if (components.length === 1) {
// Return the base widget
return (
<Component
style={{ ...containerStyling, ...widgetStyling }}
{...widgetProps}
{...{ ...widgetProps, ...pvProps }}
/>
);
}
// If container styling is not empty, use it on the wrapper widget
// and pass on an empty object, otherwise wrap and move down
else {
return (
<Component style={containerStyling} {...containerProps}>
<Component
style={containerStyling}
{...{ ...containerProps, ...pvProps }}
>
{recursiveWrapping(
remainingComponents,
{ height: "100%", width: "100%" },
widgetStyling,
containerProps,
widgetProps
widgetProps,
pvProps
)}
</Component>
);
Expand All @@ -169,15 +180,9 @@ const WrappedComponents = (props: {
props.components,
props.containerStyling,
props.widgetStyling,
props.containerProps,
props.widgetProps,
{
...props.containerProps,
pvName: effectivePvName,
connected: connected,
readonly: readonly,
value: latestValue
},
{
...props.widgetProps,
pvName: effectivePvName,
connected: connected,
readonly: readonly,
Expand Down

0 comments on commit e25a569

Please sign in to comment.