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

Fix aliased default options #567

Merged
merged 3 commits into from
Dec 29, 2017
Merged

Conversation

tbekolay
Copy link
Contributor

I recently updated to interact.js 1.3.0 so I could use restrictSize and restrictEdges when resizing. However, when I updated, I got the following behavior when resizing an element that was working correctly with version 1.2.9.

interact

Resizing from the top edge is completely messed up. I tried to reproduce this in isolation in this codepen, but in isolation this worked fine.

I dug a little deeper, and as it turned out, the top edge was being snapped down to nothing because of what was set in restrictEdges.outer. I found this odd because I had not set restrictedEdges.outer for this svg rect. However, I had set restrictEdges.outer in another file. As it turns out, I had set restrictEdges.outer to an element that was on the bottom of the screen, and since this setting bled out to the svg rect, resizing from the top immediately tried to respect the restriction, which was at the very bottom of the page.

This was an annoying bug to track down, but fortunately it was relatively easy to figure out the fix. In Interactable.js, extend is used in several places to copy defaults. However, extend does not make a copy of what it is extending, which in this specific case was causing my problem. The per action default object was being set (aliased) and then modified by the first interactable.

While the bug was somewhat easy to fix, it was unfortunately not very easy for me to test. I could not find another test that made an Interactable, so I did my best to make one. It took quite a few iterations to get something that would run and reproduce the error. I will defer to you, @taye, to fix up the test if it could be made better. But it would be great to have the bug fixed so I can use restrictEdges and restrictSize in my project :)

@taye
Copy link
Owner

taye commented Dec 18, 2017

Thank you, @tbekolay! I spotted this error while I was refactoring some things and have already fixed it on the master branch.

I've created a "v1.3-bugfix" branch so if you change the merge target from "master" to "v1.3-bugfix", then I can accept this pull request and release v1.3.3. I'll also try to merge into master manually to use your tests and clone.js module.

@tbekolay tbekolay changed the base branch from master to v1.3-bugfix December 19, 2017 15:51
Because extend does a shallow copy of object properties, some
options in interactable objects were aliased to objects in
the default objects. In some cases, setting options on one
interactable would bleed over to interactables made subsequently.

This commit adds a clone utility which is similar to extend,
but makes new objects instead of aliasing them. This allow the
newly added tests to pass.
@tbekolay tbekolay force-pushed the fix-peraction-alias branch from 3e88b82 to 7db5cc4 Compare December 19, 2017 21:16
@tbekolay
Copy link
Contributor Author

tbekolay commented Dec 19, 2017

That all sounds great, thanks! I changed the target of this PR and rebased my branch to v1.3-bugfix.

I had to make a small change to my test, but it passes now; unfortunately I get a test failure in Interaction.start now that I can't figure out... see the TravisCI test

@taye taye merged commit b4839f0 into taye:v1.3-bugfix Dec 29, 2017
taye pushed a commit that referenced this pull request Jan 2, 2018
Because extend does a shallow copy of object properties, some
options in interactable objects were aliased to objects in
the default objects. In some cases, setting options on one
interactable would bleed over to interactables made subsequently.

This commit adds a clone utility which is similar to extend,
but makes new objects instead of aliasing them. This allow the
newly added tests to pass.

Re: #567
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