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

Prevent position reset when props change #28

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

arkhvoid
Copy link

@arkhvoid arkhvoid commented Jan 4, 2021

Fixes #14

Currently, position will reset when props is being updated.

Added a new resetOnPropsChange props to prevent breaking changes to existing code.

Add a new `resetOnPropsChange` props to prevent breaking changes to existing code
@cdtinney
Copy link
Owner

Can you add a test for this?

@arkhvoid
Copy link
Author

@cdtinney I have added the test. Sorry for the late response...

@cdtinney
Copy link
Owner

No problem - can you change this to merge into develop, and rebase on develop? Thanks!

@arkhvoid arkhvoid changed the base branch from master to develop January 31, 2021 18:19
README.md Outdated Show resolved Hide resolved
@@ -23,6 +23,17 @@ describe('Marquee', () => {
});
});

it('does not reset the position when resetOnPropsChange is set to false on prop updates', (done) => {
Copy link
Owner

Choose a reason for hiding this comment

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

Can we add a test for when resetOnPropsChange is true, even though it's the default? i.e. mock the timer, make the text scroll halfway across, then change the props?

We can probably use something like https://github.com/alexreardon/raf-stub

Copy link
Author

Choose a reason for hiding this comment

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

It is possible to do animation in jest? inner.clientWidth seems to always be 0 which make the position never correct.

The only thing I can thinks of is compare the current _pos.x to the _getInitialPosition() when props changed, which again, not going to work when the position is incorrect.

I have went through the library you suggested, it seems like a library that help us doing stuff between every raf, handy though, but again, we can't do anything without correct position.

I'm not good in jest actually, if you do know how to do it correctly and have time to do so, simply close this pr and do you own changes, don't worry about me haha. But I am willing to help.

Copy link
Owner

@cdtinney cdtinney Feb 1, 2021

Choose a reason for hiding this comment

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

Ahh, sorry. It's been a while since I've worked on this. I thought I used requestAnimationFrame originally.

In this case, I think we'd be best served by an integration test that visually compares the position, e.g. checking the x-axis of the text itself after props change. This would basically mimick the visual test you're doing when you made the change.

We could add a data-test-inner-text attribute to the inner div, and check the relative position of that?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm going to pull this branch tonight and see if I can figure a test out.

@cdtinney cdtinney force-pushed the develop branch 2 times, most recently from 7830188 to 100f30a Compare February 14, 2021 03:58
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.

Pause on hover
3 participants