chunk.XX234VRK.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // src/internal/decorators.ts
  2. function event(eventName) {
  3. function legacyEvent(descriptor, protoOrDescriptor, name) {
  4. Object.defineProperty(protoOrDescriptor, name, descriptor);
  5. }
  6. function standardEvent(descriptor, element) {
  7. return {
  8. kind: "method",
  9. placement: "prototype",
  10. key: element.key,
  11. descriptor
  12. };
  13. }
  14. return (protoOrDescriptor, name) => {
  15. const descriptor = {
  16. get() {
  17. return new EventEmitter(this, eventName || (name !== void 0 ? name : protoOrDescriptor.key));
  18. },
  19. enumerable: true,
  20. configurable: true
  21. };
  22. return name !== void 0 ? legacyEvent(descriptor, protoOrDescriptor, name) : standardEvent(descriptor, protoOrDescriptor);
  23. };
  24. }
  25. var EventEmitter = class {
  26. constructor(target, eventName) {
  27. this.target = target;
  28. this.eventName = eventName;
  29. }
  30. emit(eventOptions) {
  31. const event2 = new CustomEvent(this.eventName, Object.assign({
  32. bubbles: true,
  33. cancelable: false,
  34. composed: true,
  35. detail: {}
  36. }, eventOptions));
  37. this.target.dispatchEvent(event2);
  38. return event2;
  39. }
  40. };
  41. function watch(propName) {
  42. return (protoOrDescriptor, name) => {
  43. const { updated } = protoOrDescriptor;
  44. protoOrDescriptor.updated = function(changedProps) {
  45. if (changedProps.has(propName)) {
  46. const oldValue = changedProps.get(propName);
  47. const newValue = this[propName];
  48. if (oldValue !== newValue) {
  49. this[name].call(this, oldValue, newValue);
  50. }
  51. }
  52. updated.call(this, changedProps);
  53. };
  54. };
  55. }
  56. export {
  57. event,
  58. watch
  59. };