a07950d6c2850baf64a7f387aa3fb102614c68d88a22dfe038c277ae8e229bcf622f98978b05bfecf92e2b8f7bdb31e590bc2be0d39c26382004ada71ba6c0 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var util = require('../util.js');
  5. var shared = require('@vue/shared');
  6. function getAllAliases(props, aliases) {
  7. return props.reduce((prev, cur) => {
  8. prev[cur] = cur;
  9. return prev;
  10. }, aliases);
  11. }
  12. function useWatcher(owner, props_) {
  13. const instance = vue.getCurrentInstance();
  14. const registerComplexWatchers = () => {
  15. const props = ["fixed"];
  16. const aliases = {
  17. realWidth: "width",
  18. realMinWidth: "minWidth"
  19. };
  20. const allAliases = getAllAliases(props, aliases);
  21. Object.keys(allAliases).forEach((key) => {
  22. const columnKey = aliases[key];
  23. if (shared.hasOwn(props_, columnKey)) {
  24. vue.watch(() => props_[columnKey], (newVal) => {
  25. let value = newVal;
  26. if (columnKey === "width" && key === "realWidth") {
  27. value = util.parseWidth(newVal);
  28. }
  29. if (columnKey === "minWidth" && key === "realMinWidth") {
  30. value = util.parseMinWidth(newVal);
  31. }
  32. instance.columnConfig.value[columnKey] = value;
  33. instance.columnConfig.value[key] = value;
  34. const updateColumns = columnKey === "fixed";
  35. owner.value.store.scheduleLayout(updateColumns);
  36. });
  37. }
  38. });
  39. };
  40. const registerNormalWatchers = () => {
  41. const props = [
  42. "label",
  43. "filters",
  44. "filterMultiple",
  45. "filteredValue",
  46. "sortable",
  47. "index",
  48. "formatter",
  49. "className",
  50. "labelClassName",
  51. "filterClassName",
  52. "showOverflowTooltip",
  53. "tooltipFormatter"
  54. ];
  55. const parentProps = ["showOverflowTooltip"];
  56. const aliases = {
  57. property: "prop",
  58. align: "realAlign",
  59. headerAlign: "realHeaderAlign"
  60. };
  61. const allAliases = getAllAliases(props, aliases);
  62. Object.keys(allAliases).forEach((key) => {
  63. const columnKey = aliases[key];
  64. if (shared.hasOwn(props_, columnKey)) {
  65. vue.watch(() => props_[columnKey], (newVal) => {
  66. instance.columnConfig.value[key] = newVal;
  67. });
  68. }
  69. });
  70. parentProps.forEach((key) => {
  71. if (shared.hasOwn(owner.value.props, key)) {
  72. vue.watch(() => owner.value.props[key], (newVal) => {
  73. instance.columnConfig.value[key] = newVal;
  74. });
  75. }
  76. });
  77. };
  78. return {
  79. registerComplexWatchers,
  80. registerNormalWatchers
  81. };
  82. }
  83. exports["default"] = useWatcher;
  84. //# sourceMappingURL=watcher-helper.js.map