Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Feature/victory brush #190

Merged
merged 7 commits into from
Jan 30, 2017
Merged

Feature/victory brush #190

merged 7 commits into from
Jan 30, 2017

Conversation

boygirl
Copy link
Contributor

@boygirl boygirl commented Jan 24, 2017

supporting changes for VictoryBrushContainer and VictoryZoomContainer

This PR:

-Allows VictoryContainer to render either <g> or <svg> depending on the value of the standalone prop

  • Passes a timer down in context for VictorySharedEvents
  • Enhances addEvents so that evented components can pick up "parentControllerProps" from parent state (useful for VictoryZoomContainer)
  • Adds the ability to define callbacks in the events prop that will be called after setState (useful for VictoryZoomContainer resumeAnimation)

@boygirl boygirl merged commit 5ef16eb into master Jan 30, 2017
@boygirl boygirl deleted the feature/victory-brush branch January 30, 2017 17:21
@@ -148,12 +148,22 @@ export default {
parseEvent(eventReturn, eventKey);
};

const compileCallbacks = (eventReturn) => {
const getCallback = (obj) => isFunction(obj.callback) && obj.callback;
Copy link
Contributor

Choose a reason for hiding this comment

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

This function doesn't return a constant type. It can return false or a callback function. && technically allows this function but typically I see the final return being used as a boolean, rather than as one of different possible types. I would probably just _.get(obj, 'callback') here instead to get function/undefined instead of function/boolean. Ideally we could enforce that obj.callback has to be a function and then just be able to trust in its type at this point.

@@ -148,12 +148,22 @@ export default {
parseEvent(eventReturn, eventKey);
};

const compileCallbacks = (eventReturn) => {
const getCallback = (obj) => isFunction(obj.callback) && obj.callback;
const callbacks = Array.isArray(eventReturn) ?
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the uncertainty here is whether eventReturn is a single event object or an array of one or more of them. Why don't we just coerce this into an array initially and then we can map this without question?

const getCallback = (obj) => isFunction(obj.callback) && obj.callback;
const callbacks = Array.isArray(eventReturn) ?
eventReturn.map((evtObj) => getCallback(evtObj)) : [getCallback(eventReturn)];
const callbackArray = callbacks.filter((callback) => callback !== false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if we change it to undefined callbacks instead of false, this is just callbacks.filter(_.identity). Which is the same as _.compact(callbacks)

const callbacks = Array.isArray(eventReturn) ?
eventReturn.map((evtObj) => getCallback(evtObj)) : [getCallback(eventReturn)];
const callbackArray = callbacks.filter((callback) => callback !== false);
return callbackArray.length ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not return a consistent type here? Triggering an empty list of callbacks will just result in nothing happening, which seems like a generally appropriate behavior. Is there some kind of special behavior for the 0 callbacks case that needs to be considered post-compile?

this.getSharedEventState = sharedEvents && isFunction(sharedEvents.getEventState) ?
sharedEvents.getEventState : () => undefined;
this.baseProps = this.getBaseProps(props);
this.dataKeys = Object.keys(this.baseProps).filter((key) => key !== "parent");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably use reject here ("Reject parent keys" rather than "use keys that aren't parent"). It reads easier to me. Not sure if you're into using both reject and filter though, or if you're trying to minimize dependency on lodash.

const { title, desc, portalComponent, className, standalone } = props;
return standalone ?
(
<svg {...svgProps} style={style} className={className}>
Copy link
Contributor

Choose a reason for hiding this comment

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

https://facebook.github.io/react/docs/react-api.html#createelement

Since only the type is different here, this could be refactored by using React.createElement directly instead of JSX and then just changing the type argument based on the value of standalone.

const baseParentProps = defaults({}, parentState, sharedParentState);
const parentPropsList = baseParentProps.parentControlledProps;
const parentProps = parentPropsList ? pick(baseParentProps, parentPropsList) : {};
const modifiedProps = defaults({}, parentProps, props);
Copy link
Contributor

Choose a reason for hiding this comment

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

General question - it looks like defaults acts basically as a reverse-priority merge, but I also see merge used in this repo. Is there a standard you prefer?

@@ -12,13 +12,30 @@ export default {
}
},

getTransformationMatrix(svg) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll have to learn more about svg before I can give a good review of this section.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants