-
-
Notifications
You must be signed in to change notification settings - Fork 43
Feature: useDeferred(...) #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
node_modules/ | ||
dist/ | ||
coverage/ | ||
.vscode/ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
return { | ||
TNG, useState, useReducer, useEffect, | ||
useMemo, useCallback, useRef, | ||
useMemo, useCallback, useRef, useDeferred | ||
}; | ||
|
||
|
||
|
@@ -295,5 +295,23 @@ | |
else { | ||
throw new Error("useRef() only valid inside an Articulated Function or a Custom Hook."); | ||
} | ||
} | ||
} | ||
|
||
function useDeferred() { | ||
if (getCurrentBucket()) { | ||
const [deferred] = useState((function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Area: Would love some insight on other ways to generate a Deferred object as an initial value. an IIFE that creates one was the best that I could come up with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you can do this without support form upstream, what's the value of this being included here? You're setting yourself up for a leaking batteries problem, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand what you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the value in having this function implemented in this package. Can you help me understand why you see value in that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Derp, never mind me. Just realized that this was invited by getify on #17. I don't think it's wise to lump stuff together before there's good evidence for it being the default, but I also don't think it's wise to go against the maintainer's view. |
||
let resolve, reject; | ||
let pr = new Promise((res, rej) => { | ||
resolve = res; | ||
reject = rej; | ||
}) | ||
|
||
return { pr, resolve, reject } | ||
})()) | ||
|
||
return deferred | ||
} else { | ||
throw new Error("useDeferred() only valid inside an Articulated Function or a Custom Hook.") | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normally have
formatOnSave
set to true, so for this repo specifically I set it to false. Didn't want to pollute it with my editor settings so I figured this would be the best course of action.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd instead add stuff to your
.git/info/exclude
or a user-global alternative.