@elliemae/pui-app-sdk 5.18.1 → 5.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var functionDecorators_exports = {};
20
20
  __export(functionDecorators_exports, {
21
+ AsyncSingleExecution: () => AsyncSingleExecution,
21
22
  CacheUntilResolved: () => CacheUntilResolved,
22
23
  Debounce: () => Debounce,
23
24
  ImmutableArgs: () => ImmutableArgs,
@@ -156,3 +157,22 @@ function Throttle(delay = 300) {
156
157
  return descriptor;
157
158
  };
158
159
  }
160
+ function AsyncSingleExecution(_target, _propertyKey, descriptor) {
161
+ const originalMethod = descriptor.value;
162
+ const promiseMap = /* @__PURE__ */ new Map();
163
+ descriptor.value = function(...args) {
164
+ const key = JSON.stringify(args);
165
+ if (promiseMap.has(key)) {
166
+ return promiseMap.get(key);
167
+ }
168
+ const promise = originalMethod.apply(this, args);
169
+ if (promise instanceof Promise) {
170
+ promiseMap.set(key, promise);
171
+ promise.finally(() => {
172
+ promiseMap.delete(key);
173
+ });
174
+ }
175
+ return promise;
176
+ };
177
+ return descriptor;
178
+ }
@@ -43,7 +43,7 @@ const getViewportSize = () => ({
43
43
  window.innerHeight || 0
44
44
  )
45
45
  });
46
- const convertBreakpointToNumber = (breakpoint) => Number(breakpoint.replace("px", ""));
46
+ const convertBreakpointToNumber = (breakpoint) => Number(breakpoint?.replace("px", ""));
47
47
  const getCurrentBreakpoint = () => {
48
48
  const { width } = getViewportSize();
49
49
  const { breakpoints } = (0, import_pui_theme.getDefaultTheme)();
@@ -127,7 +127,27 @@ function Throttle(delay = 300) {
127
127
  return descriptor;
128
128
  };
129
129
  }
130
+ function AsyncSingleExecution(_target, _propertyKey, descriptor) {
131
+ const originalMethod = descriptor.value;
132
+ const promiseMap = /* @__PURE__ */ new Map();
133
+ descriptor.value = function(...args) {
134
+ const key = JSON.stringify(args);
135
+ if (promiseMap.has(key)) {
136
+ return promiseMap.get(key);
137
+ }
138
+ const promise = originalMethod.apply(this, args);
139
+ if (promise instanceof Promise) {
140
+ promiseMap.set(key, promise);
141
+ promise.finally(() => {
142
+ promiseMap.delete(key);
143
+ });
144
+ }
145
+ return promise;
146
+ };
147
+ return descriptor;
148
+ }
130
149
  export {
150
+ AsyncSingleExecution,
131
151
  CacheUntilResolved,
132
152
  Debounce,
133
153
  ImmutableArgs,
@@ -17,7 +17,7 @@ const getViewportSize = () => ({
17
17
  window.innerHeight || 0
18
18
  )
19
19
  });
20
- const convertBreakpointToNumber = (breakpoint) => Number(breakpoint.replace("px", ""));
20
+ const convertBreakpointToNumber = (breakpoint) => Number(breakpoint?.replace("px", ""));
21
21
  const getCurrentBreakpoint = () => {
22
22
  const { width } = getViewportSize();
23
23
  const { breakpoints } = getDefaultTheme();
@@ -99,3 +99,35 @@ export declare function QueueTask(_target: unknown, _key: string, descriptor: Pr
99
99
  * }
100
100
  */
101
101
  export declare function Throttle(delay?: number): (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
102
+ /**
103
+ * AsyncSingleExecution decorator ensures that multiple concurrent calls to an async function
104
+ * with the same arguments will return the same promise instance until it resolves.
105
+ * Once resolved, subsequent calls will trigger a new execution.
106
+ * @param _target
107
+ * @param _propertyKey
108
+ * @param descriptor
109
+ * @returns {Function} A function that modifies the property descriptor.
110
+ * @example
111
+ * ```typescript
112
+ * import { AsyncSingleExecution } from './functionDecorators';
113
+ *
114
+ * class Example {
115
+ * @AsyncSingleExecution
116
+ * async fetchData(id: number) {
117
+ * console.log('Fetching data for', id);
118
+ * return new Promise(resolve => setTimeout(() => resolve(id), 1000));
119
+ * }
120
+ * }
121
+ *
122
+ * const instance = new Example();
123
+ * const promise1 = instance.fetchData(1);
124
+ * const promise2 = instance.fetchData(1);
125
+ *
126
+ * console.log(promise1 === promise2); // true
127
+ * ```
128
+ *
129
+ * // Output:
130
+ * // Fetching data for 1 (only logged once)
131
+ * ```
132
+ */
133
+ export declare function AsyncSingleExecution(_target: any, _propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;