simply.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { __assign, __spreadArray } from "tslib";
  2. import fmtEvent from './fmtEvent';
  3. function removeNullProps(props) {
  4. var newProps = {};
  5. for (var key in props) {
  6. if (props[key] !== null) {
  7. newProps[key] = props[key];
  8. }
  9. }
  10. return newProps;
  11. }
  12. function buildProperties(props) {
  13. var newProperties = {};
  14. for (var key in props) {
  15. var type = null;
  16. switch (typeof props[key]) {
  17. case 'string':
  18. type = String;
  19. break;
  20. case 'number':
  21. type = Number;
  22. break;
  23. case 'boolean':
  24. type = Boolean;
  25. break;
  26. }
  27. newProperties[key] = {
  28. type: type,
  29. value: props[key],
  30. };
  31. }
  32. return newProperties;
  33. }
  34. function mergeDefaultProps(defaultProps) {
  35. if (defaultProps === void 0) { defaultProps = {}; }
  36. return __assign({}, defaultProps);
  37. }
  38. function ComponentImpl(defaultProps, methods, data, mixins, instanceMethods) {
  39. Component(__assign({ props: removeNullProps(mergeDefaultProps(defaultProps)), methods: methods, mixins: mixins, data: data }, instanceMethods));
  40. }
  41. export function triggerEvent(instance, eventName, value, e) {
  42. // 首字母大写,然后加上 on
  43. var alipayCallbackName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
  44. var props = instance.props;
  45. if (props[alipayCallbackName]) {
  46. props[alipayCallbackName](value, fmtEvent(props, e));
  47. }
  48. }
  49. export function triggerEventOnly(instance, eventName, e) {
  50. // 首字母大写,然后加上 on
  51. var alipayCallbackName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
  52. var props = instance.props;
  53. if (props[alipayCallbackName]) {
  54. props[alipayCallbackName](fmtEvent(props, e));
  55. }
  56. }
  57. export function triggerEventValues(instance, eventName, values, e) {
  58. // 首字母大写,然后加上 on
  59. var alipayCallbackName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
  60. var props = instance.props;
  61. if (props[alipayCallbackName]) {
  62. props[alipayCallbackName].apply(props, __spreadArray(__spreadArray([], values, false), [fmtEvent(props, e)], false));
  63. }
  64. }
  65. export function triggerCatchEvent(instance, eventName, e) {
  66. var props = instance.props;
  67. if (props[eventName]) {
  68. props[eventName](fmtEvent(props, e));
  69. }
  70. }
  71. export function getValueFromProps(instance, propName) {
  72. var value;
  73. var props = instance.props;
  74. if (!propName) {
  75. return props;
  76. }
  77. if (typeof propName === 'string') {
  78. value = props[propName];
  79. }
  80. if (Array.isArray(propName)) {
  81. value = propName.map(function (name) { return props[name]; });
  82. }
  83. return value;
  84. }
  85. export { ComponentImpl as Component };