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

关于dataType的支持 #40

Closed
errorrik opened this issue Jun 7, 2017 · 4 comments
Closed

关于dataType的支持 #40

errorrik opened this issue Jun 7, 2017 · 4 comments

Comments

@errorrik
Copy link
Contributor

errorrik commented Jun 7, 2017

@jinzhubaofu 讨论后,确定:

  1. 只做validate,不做类型转换先
  2. dev版本支持,release版本忽略

然后是形式:

json schema

太大了,而且只能支持json定义的类型(我没好好读spec,不知道对date这种常用的复合类型支持的怎样)

react propType

https://github.com/facebook/prop-types

这种方式,除了支持基本的类型外,还:

  • 支持required
  • 支持多类型
  • 支持枚举
  • 变相支持range
  • 支持深层次结构
  • 写起来挺烦的,比如定义一个数组,其中每项包含id,age,貌似就要 PropTypes.arrayOf(PropTypes.shape({id, age})) ?

类似vue,贴近JS

dataType= {
  name: String,
  age: Number,
  addr: {
    provider: String,
    city: String
  }
}

这种方式,除了支持基本的类型外,最多能支持深层次结构,但是很多值相关的就做不了了。当然,可以开放支持function来定制校验规则。如果内置校验规则,和 react propType 也没毛区别。

来讨论下

@otakustay @jinzhubaofu 你俩觉得选哪种好

@otakustay
Copy link
Collaborator

json schema根据我和 @jinzhubaofu 先否定了,主要原因在于无法对element之类的非json类型进行校验

另一方面来说,vue也存在这样的问题,并且vue开放function支持后,早晚会变成prop types这种样子

所以综合来说,我选择prop types吧

@jinzhubaofu
Copy link
Contributor

现在看来 pro-types 只是写起来有点麻烦,其他没毛病,所以 prop types +1

@errorrik
Copy link
Contributor Author

errorrik commented Jun 9, 2017

ok,大家倾向都差不多,那 @jinzhubaofu 实现完了再关issue吧。不过我们是data不是prop,只能叫 DataTypes。

var DataTypes = san.DataTypes;
// blabla

@jinzhubaofu
Copy link
Contributor

jinzhubaofu commented Jun 12, 2017

不过我们是data不是prop,只能叫 DataTypes。

好的没问题

有个一小问题,defineComponent 出来的组件,没有组件名/类名,校验出来的报错都很难看。

所以,是否要加一个给 defineComponent 加一个 displayName 之类的东西?

jinzhubaofu pushed a commit to jinzhubaofu/san that referenced this issue Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants