-
Notifications
You must be signed in to change notification settings - Fork 524
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
New context API #1462
Merged
Merged
New context API #1462
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cfc5def
update animation context to use explicit global timer
boygirl 2f427b0
remove legacy context
boygirl e007894
prettier
boygirl 04ad255
correct zoom animation context
boygirl 3930fb2
correct timer stop in victory-container
boygirl 394e382
separate timers, improve zoom on animating charts
boygirl ff907f4
prettier
boygirl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import PropTypes from "prop-types"; | |
import * as d3Ease from "d3-ease"; | ||
import { victoryInterpolator } from "./util"; | ||
import Timer from "../victory-util/timer"; | ||
import TimerContext from "../victory-util/timer-context"; | ||
import isEqual from "react-fast-compare"; | ||
|
||
export default class VictoryAnimation extends React.Component { | ||
|
@@ -66,9 +67,7 @@ export default class VictoryAnimation extends React.Component { | |
easing: "quadInOut" | ||
}; | ||
|
||
static contextTypes = { | ||
getTimer: PropTypes.func | ||
}; | ||
static contextType = TimerContext; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
@@ -89,7 +88,7 @@ export default class VictoryAnimation extends React.Component { | |
so we bind functionToBeRunEachFrame to current instance of victory animation class | ||
*/ | ||
this.functionToBeRunEachFrame = this.functionToBeRunEachFrame.bind(this); | ||
this.getTimer = this.getTimer.bind(this); | ||
this.timer = this.getTimer(); | ||
} | ||
|
||
componentDidMount() { | ||
|
@@ -103,7 +102,7 @@ export default class VictoryAnimation extends React.Component { | |
const equalProps = isEqual(this.props, nextProps); | ||
if (!equalProps) { | ||
/* cancel existing loop if it exists */ | ||
this.getTimer().unsubscribe(this.loopID); | ||
this.timer.unsubscribe(this.loopID); | ||
|
||
/* If an object was supplied */ | ||
if (!Array.isArray(nextProps.data)) { | ||
|
@@ -124,15 +123,15 @@ export default class VictoryAnimation extends React.Component { | |
|
||
componentWillUnmount() { | ||
if (this.loopID) { | ||
this.getTimer().unsubscribe(this.loopID); | ||
this.timer.unsubscribe(this.loopID); | ||
} else { | ||
this.getTimer().stop(); | ||
this.timer.stop(); | ||
} | ||
} | ||
|
||
getTimer() { | ||
if (this.context.getTimer) { | ||
return this.context.getTimer(); | ||
if (this.context && this.context.globalTimer) { | ||
return this.context.globalTimer; | ||
} | ||
if (!this.timer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the new React context, the context should always default to the |
||
this.timer = new Timer(); | ||
|
@@ -156,13 +155,10 @@ export default class VictoryAnimation extends React.Component { | |
/* reset step to zero */ | ||
if (this.props.delay) { | ||
setTimeout(() => { | ||
this.loopID = this.getTimer().subscribe( | ||
this.functionToBeRunEachFrame, | ||
this.props.duration | ||
); | ||
this.loopID = this.timer.subscribe(this.functionToBeRunEachFrame, this.props.duration); | ||
}, this.props.delay); | ||
} else { | ||
this.loopID = this.getTimer().subscribe(this.functionToBeRunEachFrame, this.props.duration); | ||
this.loopID = this.timer.subscribe(this.functionToBeRunEachFrame, this.props.duration); | ||
} | ||
} else if (this.props.onEnd) { | ||
this.props.onEnd(); | ||
|
@@ -186,7 +182,7 @@ export default class VictoryAnimation extends React.Component { | |
} | ||
}); | ||
if (this.loopID) { | ||
this.getTimer().unsubscribe(this.loopID); | ||
this.timer.unsubscribe(this.loopID); | ||
} | ||
this.queue.shift(); | ||
this.traverseQueue(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/victory-core/src/victory-portal/portal-context.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from "react"; | ||
|
||
/** | ||
* The React context object consumers may use to access the context of the | ||
* portal. | ||
*/ | ||
const PortalContext = React.createContext({}); | ||
PortalContext.displayName = "PortalContext"; | ||
|
||
export default PortalContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
import Timer from "./timer"; | ||
|
||
/** | ||
* The React context object consumers may use to access or override the global | ||
* timer. | ||
*/ | ||
const TimerContext = React.createContext({ globalTimer: new Timer() }); | ||
TimerContext.displayName = "TimerContext"; | ||
|
||
export default TimerContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 found that React requires you to pass the
context
constructor argument to thesuper
call in order forthis.context
to be set. Right now,this.context
is always undefined.