mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-06 04:44:16 +02:00
Fix getters in item roll data
This commit is contained in:
parent
c3b1ad271c
commit
79e54b4999
3 changed files with 37 additions and 9 deletions
|
|
@ -809,3 +809,30 @@ export function sortBy(arr, fn) {
|
|||
};
|
||||
return arr.sort(cmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a shallow copy including getters of the given object.
|
||||
* Generally used for expanding roll data without side effects
|
||||
*/
|
||||
export function shallowCopyWithGetters(obj) {
|
||||
function getAllPropertyDescriptors(obj) {
|
||||
if (!obj) {
|
||||
return Object.create(null);
|
||||
}
|
||||
|
||||
return {
|
||||
...getAllPropertyDescriptors(Object.getPrototypeOf(obj)),
|
||||
...Object.getOwnPropertyDescriptors(obj)
|
||||
};
|
||||
}
|
||||
|
||||
const props = getAllPropertyDescriptors(obj);
|
||||
const result = {};
|
||||
for (const key of Object.keys(props)) {
|
||||
const value = obj[key];
|
||||
if (key !== '__proto__' && typeof value !== 'function') {
|
||||
result[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue