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

Commit

Permalink
Merge pull request #295 from FormidableLabs/bug/react-16-error
Browse files Browse the repository at this point in the history
guard against missing state object
  • Loading branch information
boygirl authored Sep 9, 2017
2 parents a934a12 + e9e8401 commit 9c5a9d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/victory-util/add-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default (WrappedComponent, options) => {
if (isFunction(super.componentWillMount)) {
super.componentWillMount();
}
this.state = this.state || {};
const getScopedEvents = Events.getScopedEvents.bind(this);
this.getEvents = partialRight(Events.getEvents.bind(this), getScopedEvents);
this.getEventState = Events.getEventState.bind(this);
Expand Down
20 changes: 11 additions & 9 deletions src/victory-util/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
// returns the original base props or base state of a given target element
const getTargetProps = (identifier, type) => {
const { childName, target, key } = identifier;
const baseType = type === "props" ? baseProps : this.state;
const baseType = type === "props" ? baseProps : this.state || {};
const base = (childName === undefined || childName === null || !baseType[childName]) ?
baseType : baseType[childName];
return key === "parent" ? base.parent : base[key] && base[key][target];
Expand Down Expand Up @@ -108,16 +108,17 @@ export default {
const mutatedProps = mutation(
assign({}, mutationTargetProps, mutationTargetState), baseProps
);
const childState = this.state[childName] || {};
const baseState = this.state || {};
const childState = baseState[childName] || {};
const extendState = (state) => {
return target === "parent" ?
extend(state[key], mutatedProps) : extend(state[key], { [target]: mutatedProps });
};
return childName !== undefined && childName !== null ?
extend(this.state, {
extend(baseState, {
[childName]: extend(childState, { [key]: extendState(childState) })
}) :
extend(this.state, { [key]: extendState(this.state) });
extend(baseState, { [key]: extendState(baseState) });
};

// returns entire mutated state for a given childName
Expand Down Expand Up @@ -197,14 +198,15 @@ export default {
* a particular element
*/
getEventState(eventKey, namespace, childType) {
const state = this.state || {};
if (!childType) {
return eventKey === "parent" ?
this.state[eventKey] && this.state[eventKey][namespace] || this.state[eventKey] :
this.state[eventKey] && this.state[eventKey][namespace];
state[eventKey] && state[eventKey][namespace] || state[eventKey] :
state[eventKey] && state[eventKey][namespace];
}
return this.state[childType] &&
this.state[childType][eventKey] &&
this.state[childType][eventKey][namespace];
return state[childType] &&
state[childType][eventKey] &&
state[childType][eventKey][namespace];

},

Expand Down

0 comments on commit 9c5a9d4

Please sign in to comment.