Skip to content

Commit

Permalink
refactor(xod-client): unify computation of renderable pin type
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenykochetkov committed Jul 31, 2018
1 parent 64d86c7 commit dd0f352
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
16 changes: 7 additions & 9 deletions packages/xod-client/src/project/components/Pin.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import R from 'ramda';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { foldEither } from 'xod-func-tools';
import { isGenericType, PIN_DIRECTION } from 'xod-project';

import { getRenderablePinType } from '../utils';

import {
PIN_RADIUS,
PIN_INNER_RADIUS,
Expand Down Expand Up @@ -52,14 +52,12 @@ const Pin = props => {
'is-output': isOutput,
});

const deducedType = props.deducedType
? foldEither(R.always('conflicting'), R.identity, props.deducedType)
: null;
const renderableType = getRenderablePinType(props);

const hasConflictingBoundValue =
deducedType === 'conflicting' && !props.isConnected && !!props.value;
renderableType === 'conflicting' && !props.isConnected && !!props.value;

const symbolClassNames = classNames('symbol', props.type, deducedType, {
const symbolClassNames = classNames('symbol', renderableType, {
hasConflictingBoundValue,
'is-connected': props.isConnected,
'is-invalid': props.isInvalid,
Expand Down Expand Up @@ -99,9 +97,9 @@ const Pin = props => {
{...pinCircleCenter}
r={PIN_RADIUS}
/>
{deducedType && props.isConnected ? (
{props.deducedType && props.isConnected ? (
<circle
className={classNames('symbol', 'is-connected', deducedType)}
className={classNames('symbol', 'is-connected', renderableType)}
{...pinCircleCenter}
r={PIN_INNER_RADIUS}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as R from 'ramda';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { maybeProp, foldMaybe, foldEither } from 'xod-func-tools';
import * as XP from 'xod-project';

import { getRenderablePinType } from '../../utils';
import NodeLabel from './NodeLabel';

const polygonPointsGetters = {
Expand Down Expand Up @@ -32,14 +32,7 @@ const BusNodeBody = ({ type, size, pins, label }) => {
};

const dataType = R.compose(
foldMaybe(
XP.PIN_TYPE.T1,
foldEither(
R.always('conflicting'),
R.unless(XP.isBuiltInType, R.always('custom'))
)
),
maybeProp('deducedType'),
getRenderablePinType,
R.head, // bus nodes have exactly one pin
R.values
)(pins);
Expand Down
18 changes: 10 additions & 8 deletions packages/xod-client/src/project/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as R from 'ramda';
import { Maybe } from 'ramda-fantasy';
import * as XP from 'xod-project';
import { foldMaybe, foldEither } from 'xod-func-tools';
import { maybeProp, foldMaybe, foldEither } from 'xod-func-tools';

import {
getOptimalPanningOffset,
Expand Down Expand Up @@ -142,10 +142,12 @@ export const isNotImplementedInXodNode = R.compose(
XP.getNodeType
);

export const getRenderablePinType = pin => {
const { deducedType } = pin;

return deducedType
? foldEither(R.always('conflicting'), R.identity, deducedType)
: XP.getPinType(pin);
};
export const getRenderablePinType = pin =>
R.compose(
R.unless(XP.isBuiltInType, R.always('custom')),
foldMaybe(
XP.getPinType(pin),
foldEither(R.always('conflicting'), R.identity)
),
maybeProp('deducedType')
)(pin);

0 comments on commit dd0f352

Please sign in to comment.