Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Feature: usePromisify(..) #16

Open
getify opened this issue Jan 14, 2019 · 6 comments
Open

Feature: usePromisify(..) #16

getify opened this issue Jan 14, 2019 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@getify
Copy link
Owner

getify commented Jan 14, 2019

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:

  1. 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(..) and useEffect(..), we'd allow optional guards to override and re-define, if closure was required.

  2. 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.

@getify getify added enhancement New feature or request help wanted Extra attention is needed labels Jan 18, 2019
@getify getify changed the title Feature: usePromise(..) Feature: usePromisify(..) Jan 18, 2019
@sbaidon
Copy link

sbaidon commented Jan 31, 2019

I would love to help on this if possible I just might need a bit of guidance!

@getify
Copy link
Owner Author

getify commented Jan 31, 2019

@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. :)

@sbaidon
Copy link

sbaidon commented Feb 5, 2019

Got it 👍

@getify
Copy link
Owner Author

getify commented Feb 5, 2019

hoping to give this some work this week. :)

@phenax
Copy link

phenax commented Oct 2, 2019

@getify, Can I take this up?

@getify
Copy link
Owner Author

getify commented Oct 2, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants