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

Bugfix/keep pushable #304

Merged
merged 19 commits into from
Feb 27, 2018
Merged

Conversation

Robin-front
Copy link
Contributor

@Robin-front Robin-front commented Aug 10, 2017

trace: #159
when check the values in componentWillReceiveProps function, you use map but no index or Corresponding handle. The handle will be always what you are move.
Then it invoke ensureValueNotConflict function, but ensureValueNotConflict just return prev or next handle value. (I think it should in consideration of thershold)

So the gap of pushable not work when allowCross=false and set the value props (to update the display at each state)

I just do it. but maybe someone has more elegant code. Many places invoke trimAlignValue func, so it may not index and nextProps args sometimes.

base issue #159 , after fixed, I make some examples:
all examples I set pushable={10} and allowCross={false}

pushable

pushable2

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 62.069% when pulling dd6c61a on Robin-front:bugfix/keep-pushable into caf5866 on react-component:master.

@paranoidjk
Copy link
Member

@Robin-front Could you add some test case about the problem you want to fix?

@coveralls
Copy link

Coverage Status

Coverage increased (+2.05%) to 63.793% when pulling 2f3e18a on Robin-front:bugfix/keep-pushable into caf5866 on react-component:master.

@paranoidjk
Copy link
Member

close #347

@paranoidjk
Copy link
Member

@Robin-front Could you pleasse rebase master? I add a Controlled Range, not allow across demo in example, and run with you fix, still got problem when handle i is pushed to i+1, then any of other handle being not moveable.

src/Range.jsx Outdated
const state = this.state || {};
const { handle, bounds } = state;
const { bounds } = state;
const handle = (i === undefined) ? state.handle : i;
Copy link
Member

Choose a reason for hiding this comment

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

In which case i could be undefiend?

Copy link
Contributor Author

@Robin-front Robin-front Oct 26, 2017

Choose a reason for hiding this comment

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

yes, because ensureValueNotConflict invoked by trimAlignValue, then trimAlignValue was invoked many place.
sometimes, only trim current handle value ( didn't pass index, like calcValueByPos in createSlider.jsx ) , but others, maybe map all handle values to trim.

if (!allowCross && handle != null) {
if (handle > 0 && val <= bounds[handle - 1]) {
return bounds[handle - 1];
if (!allowCross && handle != null && bounds !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

bounds shouldn't be undefined either ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when init component, trimAlignValue invoked in constructor, at the time this.state is undefined, bounds also.
anyway, it must walk over this function to return origin val

if (handle > 0 && val <= bounds[handle - 1]) {
return bounds[handle - 1];
if (!allowCross && handle != null && bounds !== undefined) {
if (handle > 0 && val <= (bounds[handle - 1] + thershold)) {
Copy link
Member

Choose a reason for hiding this comment

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

Actually, handle is a array index, so it should always greater than 0

Copy link
Contributor Author

@Robin-front Robin-front Oct 26, 2017

Choose a reason for hiding this comment

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

No, handle will be null only one moment when init component, constructor init state this.state = { handle: null, recent, bounds, };

once click any handle, handle will be no more null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, sorry, I am mistaken about you.
Here should be judge safe distance of the handle and surrounding handles.
handle is index, handle <= bounds.length-1 && handle >= 0, with equal.

}
if (handle < bounds.length - 1 && val >= bounds[handle + 1]) {
return bounds[handle + 1];
if (handle < bounds.length - 1 && val >= (bounds[handle + 1] - thershold)) {
Copy link
Member

Choose a reason for hiding this comment

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

same as below, handle < bounds.length - 1 should always be true.

@Robin-front
Copy link
Contributor Author

@paranoidjk
Yes, It seems have any other problem after merge master.
Same with you, any of other handle being not moveable. look like focus the same handle again.
I will check.

@Robin-front
Copy link
Contributor Author

@paranoidjk
The problem about handle cannot move is resolve already. The reason is I add extra mouseup event, so onEnd does not trigger.

And the CI test error below seems RangeWithTooltip error.
my local test cases are all passed.

@paranoidjk
Copy link
Member

paranoidjk commented Oct 26, 2017

The onEnd bug should be fixed in 18d4fa3 already

@Robin-front
Copy link
Contributor Author

Robin-front commented Oct 26, 2017

Yes, but this mouseup function was add by another PR, I think it is redundant code now.

Because when call addMouseEvent, mouseup has add to ownerDocument already. It will trigger onEnd, then onEnd will removeEvent also.

src/Range.jsx Outdated
@@ -261,23 +261,24 @@ class Range extends React.Component {
return true;
}

trimAlignValue(v, nextProps = {}) {
trimAlignValue(v, handle = this.state.handle, nextProps = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but args handle & nextProps both optional. So, I think it dosen't matter.

@paranoidjk
Copy link
Member

paranoidjk commented Nov 3, 2017

Add another demo of allowCross false && pushable true Range, both have bug right now 😅 9bbc8b1

@paranoidjk paranoidjk added the bug label Nov 3, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.1%) to 63.636% when pulling 8437ce8 on Robin-front:bugfix/keep-pushable into e296bd5 on react-component:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.1%) to 63.636% when pulling de05632 on Robin-front:bugfix/keep-pushable into e296bd5 on react-component:master.

@Robin-front
Copy link
Contributor Author

@paranoidjk
After merge master into my branch, it works well now. I can't reproduce.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.7%) to 74.609% when pulling 79c091e on Robin-front:bugfix/keep-pushable into db32618 on react-component:master.

@Robin-front
Copy link
Contributor Author

@paranoidjk
Please checkout my lastest codes and review again.

trace: #226 #379

@paranoidjk
Copy link
Member

@Robin-front Have you test the demo you added in this PR, pushable is still broken.

@Robin-front
Copy link
Contributor Author

Robin-front commented Dec 20, 2017

@paranoidjk
This is official online example, it's broken.
offical

This is my pr, local example, it works well:
notallowcross

@coveralls
Copy link

coveralls commented Dec 20, 2017

Coverage Status

Coverage increased (+5.9%) to 87.08% when pulling c4522e7 on Robin-front:bugfix/keep-pushable into c7f6f22 on react-component:master.

@paranoidjk paranoidjk requested a review from benjycui December 20, 2017 06:54
onMouseUp = () => {
this.onEnd();
this.removeDocumentEvents();
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this callback removed? Will cause a memory leak if we don't remove listeners from the document.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, listeners will be removed in onMouseDown.

Copy link
Contributor Author

@Robin-front Robin-front Feb 26, 2018

Choose a reason for hiding this comment

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

No, not onMouseDown.
Actually, listeners will be removed in this.onEnd, when another mouseup event that bind on document was trigger.

So, mouseUp event bind on Slide is repeated with another mouseUp bind on document.(trace: #361 )

this.onMouseUpListener = addEventListener(this.document, 'mouseup', this.onEnd);

slider/src/Range.jsx

Lines 111 to 115 in c7f6f22

onEnd = () => {
this.setState({ handle: null });
this.removeDocumentEvents();
this.props.onAfterChange(this.getValue());
}

@yesmeck
Copy link
Member

yesmeck commented Feb 24, 2018

@Robin-front Examples look good, could you rebase master, then I can merge it.

@yesmeck yesmeck merged commit 7c82832 into react-component:master Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants