feat: bindAllMethods util function#1476
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1476 +/- ##
==========================================
+ Coverage 45.75% 45.77% +0.02%
==========================================
Files 515 517 +2
Lines 35073 35116 +43
Branches 8784 8792 +8
==========================================
+ Hits 16048 16076 +28
- Misses 18974 18989 +15
Partials 51 51
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
| instance[methodName] as (...args: unknown[]) => unknown | ||
| ).bind(instance) as T[typeof methodName]; |
There was a problem hiding this comment.
Since you have to cast here anyway, I don't think the generic type is worth the added complexity
| let current = instance; | ||
|
|
||
| // Traverse the prototype chain until we get to Object.prototype | ||
| while (current != null && current !== Object.prototype) { |
There was a problem hiding this comment.
Might not want to iterate all the way back through the prototype chain? Not sure if this could cause anything to break in a React class component if it were used in one
There was a problem hiding this comment.
Yes, I had that thought as well. I could see parameterizing it with a flag or something
| current = Object.getPrototypeOf(current); | ||
| } | ||
|
|
||
| return [...methodNames.keys()].sort(); |
There was a problem hiding this comment.
Was easier for testing, but I could just sort in the test I guess
Util functions for binding all methods of an object to itself.
resolves #1474