TNG-Hooks
TNG-Hooks copied to clipboard
Feature: `usePromisify(..)`
The usePromisify(..) hook would wrap/lift a callback-expecting function as a promise-returning function. It would expect callback-last, and err-first-callback.
Similar to Node's util.promisify(..), this hook would allow overriding of that assumption via a Symbol added to the function in question, to define its own promisified version. In that case, the usePromisify(..) hook would just return that value and do nothing else.
The benefits of this as a hook:
-
Since it would store the promisified version in a state slot, it allows you to promisify inline function expressions safely without unnecessary work (the wrapping would only happen the first time).
Just like
useMemo(..)anduseEffect(..), we'd allow optional guards to override and re-define, if closure was required. -
It doesn't require polluting the outer/global namespace with a promisified version of the function. In other words, it allows you to only locally create a promisified override without affecting the rest of the program.
I would love to help on this if possible I just might need a bit of guidance!
@sbaidon great, thanks! happy to have the help!
I want to hold off on adding hooks briefly, while I work on the re-org in #20. But hopefully this won't take too long to finish and unblock future hooks work. :)
Got it 👍
hoping to give this some work this week. :)
@getify, Can I take this up?
I got stuck on #20 (mostly design choice wise) after getting quite a bit of work in on it. You can see that work in progress on this branch: https://github.com/getify/TNG-Hooks/tree/issue-20-externalize-context
But because of the nature of that change, it would invalidate any of these other features, so I wanted to wait on them for #20 to be finished. I do hope to get back to that work and finish it soon, but I have to work out some details of design first.