update-form-stream.js 512 B

123456789101112131415161718192021222324252627
  1. import { isEmpty } from '@cip/utils/util'
  2. export const emptySign = Symbol('empty')
  3. export class UpdateFormStream {
  4. values = []
  5. constructor (props, update) {
  6. this.update = update
  7. this.props = props
  8. this.init()
  9. }
  10. init () {
  11. this.values = []
  12. }
  13. appendValue (value) {
  14. this.values[0] = isEmpty(value) ? emptySign : value
  15. }
  16. appendOtherValue (value, i = 1) {
  17. this.values[i] = isEmpty(value) ? emptySign : value
  18. }
  19. end () {
  20. this.update(this.values)
  21. this.init()
  22. }
  23. }