Skip to content

Component methods that accept a callback return a promise #2663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Component methods that accept a callback return a promise #2663

wants to merge 1 commit into from

Conversation

romanmatiasko
Copy link

Already mentioned in #2642.
All methods that accept a callback should return a promise if Promises/A+ are supported. Otherwise, they return undefined as before.

@zpao
Copy link
Member

zpao commented Dec 5, 2014

I appreciate the effort but I don't think we're ready to make this sort of commitment to our API. I'm inclined to say we close this for the time being until we figure out a consistent async story here.

@romanmatiasko
Copy link
Author

Sure, thanks for feedback.

@sophiebits sophiebits closed this Feb 26, 2015
josephsavona pushed a commit that referenced this pull request May 15, 2024
--- 

Previously, we always emitted `Memoize dep` instructions after the function 
expression literal and depslist instructions 

```js 

// source 

useManualMemo(() => {...}, [arg]) 

// lowered 

$0 = FunctionExpression(...) 

$1 = LoadLocal (arg) 

$2 = ArrayExpression [$1] 

$3 = Memoize (arg) 

$4 = Call / LoadLocal 

$5 = Memoize $4 

``` 

Now, we insert `Memoize dep` before the corresponding function expression 
literal: 

```js 

// lowered 

$0 = StartMemoize (arg)      <---- this moved up! 

$1 = FunctionExpression(...) 

$2 = LoadLocal (arg) 

$3 = ArrayExpression [$2] 

$4 = Call / LoadLocal 

$5 = FinishMemoize $4 

``` 

Design considerations: 

- #2663 needs to understand which lowered instructions belong to a manual 
memoization block, so we need to emit `StartMemoize` instructions before the 
`useMemo/useCallback` function argument, which contains relevant memoized 
instructions 

- we choose to insert StartMemoize instructions to (1) avoid unsafe instruction 
reordering of source and (2) to ensure that Forget output does not change when 
enabling validation 

This PR only renames `Memoize` -> `Start/FinishMemoize` and hoists 
`StartMemoize` as described. The latter may help with stricter validation for 
`useCallback`s, although testing is left to the next PR. 

#2663 contains all validation changes
josephsavona pushed a commit that referenced this pull request May 15, 2024
--- 

Previously (in #2663), we check that inferred dependencies exactly match source 
dependencies. As @validatePreserveExistingMemoizationGuarantees checks that 
Forget output does not invalidate *any more* than source, we now allow more 
specific inferred dependencies when neither the inferred dep or matching source 
dependency reads into a ref (based on `.current` access). 

See added comments for more details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants