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

Improved drag flow #172

Merged
merged 6 commits into from
Nov 16, 2017
Merged

Improved drag flow #172

merged 6 commits into from
Nov 16, 2017

Conversation

alexreardon
Copy link
Collaborator

Less setTimeout craziness - and a much more solid flow as a result!

if (state.phase !== 'IDLE' && state.phase !== 'DRAG_COMPLETE') {
dispatch(clean());
// drag cancelled before timeout finished
if (state.phase !== 'PREPARING') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previously we had no way of knowing if the drag was ended before this first timeout was fired. It is possible to do with a well orchestrated force press in touch dragging. By adding an extra phase we can know if something has changed in the elapsed time.

@alexreardon
Copy link
Collaborator Author

To be a good citizen I also wrote some tests for the lift action-creator. Hopefully this will assist in preventing regressions in this super important part of the code

@@ -55,14 +55,6 @@ export const requestDimensions = (type: TypeId): RequestDimensionsAction => ({
payload: type,
});

export type BeginLiftAction = {|
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no longer needed

@@ -0,0 +1,249 @@
// @flow
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All new tests! 💃

console.error('cannot drop if not dragging', state);
// We need to wrap this in a setTimeout to avoid a race
// condition with `lift`, which includes timeouts
setTimeout(() => dispatch(clean()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yuck. this is gone! 🎉

// When a drag starts we need to flush any existing animations
// that might be occurring. While this flush is occurring we
// are in this phase
'PREPARING' |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

new phase to allow for flushing

expect(console.error).toHaveBeenCalled();
});

it('should not begin a lift if the drag is cancelled while the animations are flushing', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test executes a current error case - which is what caused me to make this change

Copy link
Contributor

@jaredcrowe jaredcrowe left a comment

Choose a reason for hiding this comment

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

new tests look super helpful dude

@alexreardon alexreardon merged commit 41101c7 into master Nov 16, 2017
@alexreardon alexreardon deleted the improved-drag-flow branch November 16, 2017 03:45
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.

2 participants