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

fix create container #569

Merged
merged 1 commit into from
Feb 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/components/containers/create-container.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toPairs, groupBy, forOwn, includes, flow } from "lodash";
import { toPairs, groupBy, forOwn, includes, flow, isEmpty, isFunction } from "lodash";
import { VictoryContainer, Log } from "victory-core";

import { voronoiContainerMixin } from "./victory-voronoi-container";
Expand Down Expand Up @@ -43,15 +43,17 @@ const combineDefaultEvents = (defaultEvents) => {
// takes a defaultEvents array and returns one equal or lesser length,
// by combining any events that have the same target
const eventsByTarget = groupBy(defaultEvents, "target");
return toPairs(eventsByTarget).map(
const events = toPairs(eventsByTarget).map(
([target, eventsArray]) => {
return {
eventsArray = eventsArray.filter(Boolean);
return isEmpty(eventsArray) ? null : {
target,
eventHandlers: combineEventHandlers(eventsArray.map((event) => event.eventHandlers))
// note: does not currently handle eventKey or childName
};
}
);
return events.filter(Boolean);
};

export const combineContainerMixins = (mixins, Container) => {
Expand Down Expand Up @@ -84,12 +86,15 @@ export const combineContainerMixins = (mixins, Container) => {
{}
);

static defaultEvents = combineDefaultEvents(
Classes.reduce(
(defaultEvents, Class) => ([...defaultEvents, ...Class.defaultEvents]),
[]
)
);
static defaultEvents = (props) => {
return combineDefaultEvents(
Classes.reduce((defaultEvents, Class) => {
const events = isFunction(Class.defaultEvents) ?
Class.defaultEvents(props) : Class.defaultEvents;
return ([...defaultEvents, ...events]);
}, [])
);
};

getChildren(props) {
return instances.reduce(
Expand Down