-
Notifications
You must be signed in to change notification settings - Fork 40
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: trigger onChange twice when inputting using the input method #60
fix: trigger onChange twice when inputting using the input method #60
Conversation
需要添加测试用例 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #60 +/- ##
==========================================
+ Coverage 97.31% 97.40% +0.09%
==========================================
Files 5 5
Lines 186 193 +7
Branches 68 69 +1
==========================================
+ Hits 181 188 +7
Misses 5 5 ☔ View full report in Codecov by Sentry. |
已添加测试用例,主要有两点:
|
cutValue = countConfig.exceedFormatter(currentValue, { | ||
max: countConfig.max, | ||
if (isExceed(currentValue)) { | ||
cutValue = countConfig.exceedFormatter!(currentValue, { |
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.
这里不要使用!
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.
isExceed
里确实判断,看有没有更好的代替?
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.
我目前能想到的还有一个思路是:
将formatter相关的代码抽离出来,返回一个cutValue和isExceed
const { cutValue, isExceed } = onInternalFormatter(e.currentTarget.value);
在onInternalChange
的事件中,formatter后直接触发triggerChange
在onInternalCompositionEnd
的事件中,判断是否isExceed,如果为true就触发triggerChange
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.
感觉这样会容易混淆逻辑 🤔
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.
我认为fomatter是一个独立的事情,isExceed和cutValue都是和formatter相关的内容,表示格式化后是否超出限制和最终裁剪的值。目前的处境是在change的时候需要格式化,在compositionEnd的时候需要格式化并且条件调用change
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.
改改看
}); | ||
|
||
if (currentValue !== cutValue) { | ||
setSelection([ |
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.
一个看似计算的方法,内部确在调用setSelection
, 有点奇怪
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.
有副作用
的意思。
#61 你觉得怎样? |
emmm,其实我一开始也想在triggerChange上加参数,这确实是最简单的改法。但往triggerChange这种语义化的函数中堆除了e和value之外的参数总感觉怪怪的😂如果后续再来个类似的需求,又得加参数了。 |
纯函数有些时候也不一定能保证,无非是把set值的操作再放到另外一个函数中去 |
The onCompositionEnd event will be called when the user input method combination ends, triggering an onChange event, but it only needs to be called after the count method of Input is successfully cropped.
fix ant-design/ant-design#46587
close #61