-
Notifications
You must be signed in to change notification settings - Fork 63
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
refactor: 代码优化 & 补全 e2e 测试 #161
Conversation
Deploy preview for el-form-renderer ready! Built with commit 3acdcf1 |
import getEnableWhenSatatus from './mixins/enable-when' | ||
import {noop} from './utils' | ||
import getEnableWhenSatatus from '../util/enable-when' | ||
import {noop} from '../util/utils' |
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.
写在 util/index.js,引入 ../util 就好了?
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.
暂时先这样吧:
util/utils - 通用函数
util/enable-when - getEnableWhenSatatus 的逻辑
util/transform-content - 转换 content 供内部使用的函数,这个在重构中,会更明确其意义些
Why
优化一波代码,为后续新功能铺垫。
How
大致按 commit 分。除了 format 相关的改动有后期调整
移除 package-option.js
将方法 getEnableWhenSatatus 改造成纯函数
移除 mixin-hidden
调整层级
优化 transformContent
通过函数名称明确 transformContent 的行为:
$
前缀的 key 去掉该前缀优化初始化 options & value 的函数
这两个函数的本质是,从 content 中抽取 options & default 值,并转成树🌲的形式。
这里我抽离出了共同的 collect 逻辑
明确 updateForm 的合并逻辑(结合 commit: 补回 inputFormat 功能)
这是原本的逻辑,bug 我注释其中
新的递归合并 oldV & newV 策略如下:
getFormValue(结合 commit: outputFormat 返回值是 Object 类型时要覆盖到上一层)
功能没有改动,补充了对关键转换函数的测试
删除 updateOptions
这个函数是 2018 年添加的,其监听 innerContent 的变化,然后更新内部 options。
问题是,现在的 innerContent 是一次性的,beforeMount 时生成。更新 options 已经有 setOptions 来实现了,没人直接改 content。
删了后,测试 basic, set-options, remote 几个示例正常
补回 inputFormat 功能
之前重构 updateForm 时漏掉了。这里补回并增加单测
补全 e2e 测试
终于,把关键用例的 e2e 测试补全了。不仅发现了很多之前 commit 的遗漏,还能让以后的重构更安心
Test
单元测试
通过,显然,否则不能 push
e2e 测试