@xh/hoist 76.0.0-SNAPSHOT.1758755408459 → 76.0.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.
- package/CHANGELOG.md +7 -2
- package/build/types/cmp/grid/GridModel.d.ts +0 -1
- package/build/types/cmp/grid/impl/ColumnWidthCalculator.d.ts +1 -1
- package/build/types/svc/GridAutosizeService.d.ts +1 -1
- package/build/types/utils/js/Decorators.d.ts +12 -0
- package/cmp/grid/GridModel.ts +19 -8
- package/cmp/grid/impl/ColumnWidthCalculator.ts +1 -1
- package/cmp/grid/impl/InitPersist.ts +13 -1
- package/package.json +1 -1
- package/svc/GridAutosizeService.ts +7 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/utils/js/Decorators.ts +37 -1
package/utils/js/Decorators.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import {Exception} from '@xh/hoist/exception';
|
|
8
8
|
import {debounce, isFunction} from 'lodash';
|
|
9
9
|
import {getOrCreate, throwIf} from './LangUtils';
|
|
10
|
-
import {withDebug, warnIf, withInfo} from './LogUtils';
|
|
10
|
+
import {withDebug, warnIf, withInfo, logWarn} from './LogUtils';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Decorates a class method so that it is debounced by the specified duration.
|
|
@@ -110,3 +110,39 @@ export function abstract(target, key, descriptor) {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Decorates a class method that returns a Promise so that concurrent calls with the same arguments
|
|
116
|
+
* will share a single pending Promise. Arguments must be serializable via JSON.stringify.
|
|
117
|
+
*/
|
|
118
|
+
export function sharePendingPromise<T>(target: T, key: string, descriptor: PropertyDescriptor) {
|
|
119
|
+
const fn = descriptor.value;
|
|
120
|
+
return {
|
|
121
|
+
...descriptor,
|
|
122
|
+
value: function () {
|
|
123
|
+
try {
|
|
124
|
+
const cacheKey = '_xh_' + key + JSON.stringify(arguments);
|
|
125
|
+
return getOrCreate(this, cacheKey, () => {
|
|
126
|
+
const ret = fn.apply(this, arguments);
|
|
127
|
+
if (!(ret instanceof Promise)) {
|
|
128
|
+
logWarn(
|
|
129
|
+
`@sharePendingPromise applied to non-Promise-returning method: ${key}`,
|
|
130
|
+
this.constructor.name
|
|
131
|
+
);
|
|
132
|
+
return ret;
|
|
133
|
+
}
|
|
134
|
+
return ret.finally(() => delete this[cacheKey]);
|
|
135
|
+
});
|
|
136
|
+
} catch (e) {
|
|
137
|
+
logWarn(
|
|
138
|
+
[
|
|
139
|
+
`@sharePendingPromise unable to serialize arguments for method: ${key}.`,
|
|
140
|
+
e.message
|
|
141
|
+
],
|
|
142
|
+
this.constructor.name
|
|
143
|
+
);
|
|
144
|
+
return fn.apply(this, arguments);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|