Skip to content

Conversation

@jquense
Copy link
Member

@jquense jquense commented Sep 17, 2019

No description provided.

@jquense
Copy link
Member Author

jquense commented Sep 17, 2019

We occasionally need this, like in our auth contexts

@codecov
Copy link

codecov bot commented Sep 17, 2019

Codecov Report

Merging #12 into master will increase coverage by 2.75%.
The diff coverage is 88.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #12      +/-   ##
==========================================
+ Coverage   58.14%   60.89%   +2.75%     
==========================================
  Files          27       28       +1     
  Lines         270      289      +19     
  Branches       63       65       +2     
==========================================
+ Hits          157      176      +19     
  Misses        113      113
Impacted Files Coverage Δ
src/useAnimationFrame.ts 100% <ø> (ø) ⬆️
src/useStateAsync.ts 100% <100%> (ø)
src/useMergeState.ts 66.66% <57.14%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f4ac32...bc52e71. Read the comment docs.

setState(stateBefore => {
try {
let nextState: TState
if (typeof update === 'function') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't suppose instanceof makes TS happy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does but instanceof Function is weird


useEffect(() => {
resolvers.current.forEach(resolve => resolve(state))
resolvers.current = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resolvers.current = []
resolvers.current.length = 0;

easier? :p

@jquense jquense merged commit 0db4bb4 into master Sep 20, 2019
@jquense jquense deleted the asyc-setState branch September 20, 2019 14:01
// react won't re-render and effect will not resolve. If there are already
// resolvers queued, then it should be safe to assume an update will happen
if (!resolvers.current.length && Object.is(nextState, prevState)) {
resolve(nextState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok; you could also add another "should run resolve manually flag", but i guess eagerly resolving the first few is fine

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right in the case of a bunch of sets. yeah that's a good approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants