-
Notifications
You must be signed in to change notification settings - Fork 311
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
Immutable chart state #42
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a few places where the chart object is being mutated.
Would it be easier to just deep copy it at the start of every action, or are there performance concerns?
} | ||
|
||
export const onLinkComplete: IOnLinkComplete = (props) => { | ||
const { linkId, fromNodeId, fromPortId, toNodeId, toPortId, config = {} } = props | ||
return (chart: IChart): IChart => { | ||
const links = {...chart.links}; | ||
if ((config.validateLink ? config.validateLink({ ...props, chart }) : true) && [fromNodeId, fromPortId].join() !== [toNodeId, toPortId].join()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To resolve the merge conflict, this condition needs to be updated so that it starts with !config.readonly
:
if (!config.readonly && (config.validateLink ? config.validateLink({ ...props, chart }) : true) && [fromNodeId, fromPortId].join() !== [toNodeId, toPortId].join()) {
It would be great to get this merged, as it would mean that the library could be used with hooks inside functional components! function useChart(initialState: IChart): [IChart, typeof actions] {
const [chart, setChart] = useState(initialState);
const stateActions = useMemo(
() =>
Object.entries(actions).reduce(
(prev, [key, val]) => ({
...prev,
[key]: (...args: any) => setChart(val(...args))
}),
{}
) as typeof actions,
[actions]
);
return [chart, stateActions];
} |
Is this pr being merged any time soon? Have found some bugs on the validateLink function that are caused by this. The link.to property gets wiped when the function is called. |
Fixes #31