Skip to content
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 7 commits into from
Dec 20, 2019
Merged

New context API #1462

merged 7 commits into from
Dec 20, 2019

Conversation

boygirl
Copy link
Contributor

@boygirl boygirl commented Dec 19, 2019

@fabianishere

This is my attempt at using the new context API with the current animation model. It's mostly working except for stopping animation in VictoryZoomContainer. Also, the global timer does not seem to be reliably provided, necessitating keeping the find / create code in getTimer().

Heavily influenced by #1461
closes #1442

static contextTypes = {
getTimer: PropTypes.func
};
static contextType = TimerContext;

constructor(props) {

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 the super call in order for this.context to be set. Right now, this.context is always undefined.

if (this.context.getTimer) {
return this.context.getTimer();
if (this.context && this.context.globalTimer) {
return this.context.globalTimer;
}
if (!this.timer) {

Choose a reason for hiding this comment

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

With the new React context, the context should always default to the globalTimer defined in timer-context.js in case it is not set. Thus, you can assume that this value is set and as such you don't need logic for constructing a timer here.

@fabianishere
Copy link

It seems like VictoryTransition and VictoryAnimation conflict in their use of bypassAnimation and resumeAnimation. If they are given their own timers, they work correctly.

@fabianishere
Copy link

Apparently, VictoryTransition in the master branch never receives the global timer from the context and therefore does not share it with the other components, preventing these conflicts.

@boygirl
Copy link
Contributor Author

boygirl commented Dec 20, 2019

Interesting... Let me do some work to reconcile the timers. Thank you for helping out!

@boygirl
Copy link
Contributor Author

boygirl commented Dec 20, 2019

@fabianishere Thank you so much for helping diagnose. I added explicitly separate timers for animations and transitions and everything now works as expected. I will end up merging this PR rather than the one you opened, but you are owed most of the credit for getting this improvement working. I will make sure the changelog calls out your contribution.

@boygirl boygirl changed the title [WIP] Experiment/animation with new context New context API Dec 20, 2019
@boygirl boygirl merged commit c8090c6 into master Dec 20, 2019
@boygirl boygirl deleted the experiment/animation-with-new-context branch December 20, 2019 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React.StrictMode support? (migrate to new context API)
2 participants