Skip to content

Commit fb9dd99

Browse files
committed
feat: wrapped all promises functions recursively recursively to the root prototype
1 parent 9963deb commit fb9dd99

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,21 @@ export function useAsyncDataWrapper<T extends Record<string, any>>(
6565
obj: T,
6666
): AsyncDataWrapper<T> {
6767
const composable = {} as AsyncDataWrapper<T>;
68-
const proto = Object.getPrototypeOf(obj);
6968

70-
// Get function names from the object's prototype, excluding the constructor
71-
const functionNames = Object.getOwnPropertyNames(proto).filter(
72-
key => key !== 'constructor' && typeof obj[key] === 'function',
73-
);
69+
// Get all function names from the object and its prototypes
70+
const functionNameSet = new Set<string>();
71+
let currentObj = obj;
72+
while (currentObj && currentObj !== Object.prototype) {
73+
const keys = Object.getOwnPropertyNames(currentObj);
74+
for (const key of keys) {
75+
// Exclude constructor and non-function properties
76+
if (key !== 'constructor' && typeof currentObj[key] === 'function') {
77+
functionNameSet.add(key);
78+
}
79+
}
80+
currentObj = Object.getPrototypeOf(currentObj);
81+
}
82+
const functionNames = Array.from(functionNameSet);
7483

7584
for (const key of functionNames) {
7685
// Bind the function to preserve context

0 commit comments

Comments
 (0)