handleProps.js 932 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function handleProps(opts = {}) {
  2. opts.props = opts.props || {}
  3. if (opts.relations) {
  4. opts.props.theRelations = opts.relations
  5. }
  6. if (!opts.properties) { return false }
  7. Object.keys(opts.properties)
  8. .forEach((prop) => {
  9. const val = opts.properties[prop]
  10. if (!val) {
  11. opts.props[prop] = val
  12. return false
  13. }
  14. if (typeof val === 'function') {
  15. const obj = {
  16. [Boolean]: false,
  17. [String]: '',
  18. [Array]: [],
  19. [Object]: {},
  20. }
  21. opts.props[prop] = obj[val]
  22. return false
  23. }
  24. if (val.hasOwnProperty('value')) {
  25. opts.props[prop] = val.value
  26. } else if (val.type !== 'observer') {
  27. const info = {
  28. [String]: '',
  29. [Number]: 0,
  30. [Object]: {},
  31. [null]: null,
  32. }
  33. opts.props[prop] = info[val.type]
  34. }
  35. })
  36. }
  37. module.exports = handleProps