-
Notifications
You must be signed in to change notification settings - Fork 76
Conversation
@@ -148,12 +148,22 @@ export default { | |||
parseEvent(eventReturn, eventKey); | |||
}; | |||
|
|||
const compileCallbacks = (eventReturn) => { | |||
const getCallback = (obj) => isFunction(obj.callback) && obj.callback; |
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.
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) ? |
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.
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); |
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.
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 ? |
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.
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"); |
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.
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}> |
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.
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); |
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.
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) { |
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.
I'll have to learn more about svg
before I can give a good review of this section.
supporting changes for VictoryBrushContainer and VictoryZoomContainer
This PR:
-Allows
VictoryContainer
to render either<g>
or<svg>
depending on the value of thestandalone
propVictorySharedEvents
addEvents
so that evented components can pick up "parentControllerProps" from parent state (useful for VictoryZoomContainer)