Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

调整Tabs和Drawer的beforeRemove/beforeClose处理 #688

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rayzhao99
Copy link

原因

  1. 现在的beforeRemove/beforeClose只支持通过Promise来取消关闭,但不支持在同步调用中取消;
  2. 取消操作通过reject()来实现。reject()更多用于异常情况,但取消关闭通常不算是异常;
  3. Promise可能会出现真的异常,但与取消关闭功能重合,无法区分,也增加排错难度;

实现结果

  1. 增加对同步函数的支持,即beforeRemove/beforeClose可以设置同步函数。当然,异步函数仍然支持;
  2. 同步函数返回truthy值,或Promise resolved truthy值则关闭;否则,同步返回falsy值,或Promise resolved falsy值,则取消关闭;
  3. 不再使用reject()来取消关闭(虽然事实上有此效果),reject继续用作异常处理;

问题

**兼容性问题!!!**新接口改变了API定义,与现有代码不兼容。现有代码在resolve时执行关闭,但未传入参数时,参数为undefined(falsy值),新接口中变为取消关闭。

1)同步函数,返回truthy则关闭标签页,返回falsy则不关闭;
2)异步函数,resolve truthy则关闭标签页,resolve falsy或reject则不关闭;
1)reject()更常用于异常处理,但取消关闭建议看成预期结果之一,而不是异常;
2)通过reject()取消关闭,会与异步操作中的真实异常冲突,增加排错难度;
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant