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

[discussion] api naming #20

Closed
lzfee0227 opened this issue Mar 2, 2020 · 15 comments · Fixed by #68
Closed

[discussion] api naming #20

lzfee0227 opened this issue Mar 2, 2020 · 15 comments · Fixed by #68
Labels
v3 Version 3

Comments

@lzfee0227
Copy link
Collaborator

lzfee0227 commented Mar 2, 2020

TL;DR

See conclusion in #20 (comment)


for formstate-x-next

  • validators -> addValidators
  • $
    • $ looks like a hack
    • $ should not have multiple meanings in different contexts
  • _value -> rawValue or sth else?
    • _ should actually be private, but have to be accessed outside formstate-x
      (for bind** not included & should not included)
@nighca
Copy link
Collaborator

nighca commented Mar 3, 2020

  • validators -> addValidators

I don't think it's necessary 🤔

  • $ should not have multiple meanings in different contexts

IMO we should just remove $ on FieldState

  • _ should actually be private, but have to be accessed outside formstate-x

Ideally, It should be private in module scope, not class scope. We have no module level public / private in Javascript, that's the point.

Or, maybe we can achieve that by putting bindInput on FieldState - so we can use class level private - but I don't like the API.

@lzfee0227

This comment was marked as off-topic.

@nighca

This comment was marked as off-topic.

@nighca nighca added the v2 Features or changes for v2 label Jul 3, 2020
@nighca
Copy link
Collaborator

nighca commented May 11, 2021

  • $ should not have multiple meanings in different contexts

IMO we should just remove $ on FieldState

If we can also remove $ on FormState, as we assumed in #40. All $s will be gone 🎆

@nighca nighca added v3 Version 3 and removed v2 Features or changes for v2 labels May 11, 2021
@huangbinjie
Copy link

I don't think it's necessary 🤔

It's realy matters that Function name ought start with a verb, such as getByXxx, isXxx, hasXxx

Ideally, It should be private in module scope, not class scope. We have no module level public / private in Javascript, that's the point.

Maybe index.ts can be treated as the public module, the others can be private module?

@nighca nighca mentioned this issue Jun 15, 2021
Merged
13 tasks
@nighca
Copy link
Collaborator

nighca commented Aug 21, 2021

Validatable & ComposibleValidatable -> State

@nighca
Copy link
Collaborator

nighca commented Nov 18, 2021

@lzfee0227
Copy link
Collaborator Author

FYI: Fields Input etc
另外 Proxy 通常跟 Decorator 类似,输入输出类型不变?

@nighca
Copy link
Collaborator

nighca commented Nov 22, 2021

另外 Proxy 通常跟 Decorator 类似,输入输出类型不变?

名字可以商量,有建议吗?

@nighca

This comment was marked as resolved.

@nighca
Copy link
Collaborator

nighca commented Feb 9, 2022

  • _value -> rawValue or sth else?

Maybe instantValue

_value is removed in #63

@nighca
Copy link
Collaborator

nighca commented Feb 11, 2022

Conclusion

content below may change

  • Remove _value
  • Remove $ of FieldState (maybe later back as safeValue, see details in Type-safe safeValue #58)
  • Validatable & ComposibleValidatable -> IState
  • validators -> withValidator
  • ProxyState -> TransformedState
  • disableValidationWhen -> disableWhen See disable & disable validation #17 for details

@nighca nighca linked a pull request Feb 18, 2022 that will close this issue
@nighca
Copy link
Collaborator

nighca commented Feb 18, 2022

Consider that most of the time we append validators like this:

const state = new FieldState('').validators(...)

const formState = new FormState({
  foo: new FieldState('').validators(...)
  // ...
}).validators(...)

withValidator will be better than addValidator, if you compare

const state = new FieldState('').addValidator(...)

with

const state = new FieldState('').withValidator(...)

@huangbinjie
Copy link

withValidator will be better than addValidator

介词 with 当动词用好吗,那下面这种情况看起来就不舒服了

const state = new FieldState('')
state.withValidator
// state.addValidator

另外 add 的反义词也好找点,当需要对成的接口的时候

@nighca
Copy link
Collaborator

nighca commented Feb 22, 2022

介词 with 当动词用好吗

@huangbinjie 不是把 with 当动词,而是这里就不用动词来命名了

那下面这种情况看起来就不舒服了

const state = new FieldState('')
state.withValidator
// state.addValidator

这种情况可以写成

state = state.withValidator(...)

虽然确实会麻烦一点;但是对比:

  1. 消费 validators() 的返回值

    const state = new FieldState('').validators(...)
    // 或者
    return new FormState().validators(...) 
  2. 不消费 validators() 的返回值

    const state = new FieldState('')
    state.validators(...)

显然 1 对应的场景更多,因此场景 1 下的自然程度要比场景 2 下的自然程度更重要

另外 add 的反义词也好找点,当需要对成的接口的时候

with 也好找,without 就是了..

@nighca nighca closed this as completed Feb 23, 2022
@nighca nighca mentioned this issue Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3 Version 3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants