-
-
Notifications
You must be signed in to change notification settings - Fork 777
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
Bugfix/keep pushable #304
Conversation
@Robin-front Could you add some test case about the problem you want to fix? |
close #347 |
@Robin-front Could you pleasse rebase master? I add a |
src/Range.jsx
Outdated
const state = this.state || {}; | ||
const { handle, bounds } = state; | ||
const { bounds } = state; | ||
const handle = (i === undefined) ? state.handle : i; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
@paranoidjk |
@paranoidjk And the CI test error below seems |
The onEnd bug should be fixed in 18d4fa3 already |
Yes, but this Because when call |
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 = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createSlider
will call trimAlignValue
too https://github.com/react-component/slider/search?utf8=%E2%9C%93&q=trimAlignValue&type=
There was a problem hiding this comment.
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.
Add another demo of |
@paranoidjk |
@paranoidjk |
@Robin-front Have you test the demo you added in this PR, pushable is still broken. |
@paranoidjk |
onMouseUp = () => { | ||
this.onEnd(); | ||
this.removeDocumentEvents(); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 )
slider/src/common/createSlider.jsx
Line 161 in c7f6f22
this.onMouseUpListener = addEventListener(this.document, 'mouseup', this.onEnd); |
Lines 111 to 115 in c7f6f22
onEnd = () => { | |
this.setState({ handle: null }); | |
this.removeDocumentEvents(); | |
this.props.onAfterChange(this.getValue()); | |
} |
@Robin-front Examples look good, could you rebase master, then I can merge it. |
trace: #159
when check the values in
componentWillReceiveProps
function, you usemap
but no index or Corresponding handle. The handle will be always what you are move.Then it invoke
ensureValueNotConflict
function, butensureValueNotConflict
just return prev or next handle value. (I think it should in consideration ofthershold
)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 notindex
andnextProps
args sometimes.base issue #159 , after fixed, I make some examples:
all examples I set
pushable={10}
andallowCross={false}