Skip to content
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

feat: add asyncComputed, asyncEffect #24

Merged
merged 8 commits into from
Dec 24, 2024
Merged

feat: add asyncComputed, asyncEffect #24

merged 8 commits into from
Dec 24, 2024

Conversation

johnsoncodehk
Copy link
Collaborator

Add asyncComputed, asyncEffect APIs, which is based on comma operator and function* design implementation.

Example:

const src = signal('fallback data');

const asyncComp = asyncComputed(async function* () {
  const data = await fetchSomeData();
  if (data) {
    return data;
  }
  const fallbackData = (yield src, src).get();
  return fallbackData;
});

asyncEffect(async function* () {
  const data = await (yield asyncComp, asyncComp).get();
  console.log('Effect triggered with value:', value);
});

src.set(2);

@johnsoncodehk
Copy link
Collaborator Author

This API was added for my personal needs (I will use it in https://github.com/volarjs/volar.js), and its usage will probably not meet most people's expectations. Therefore this feature will be unstable and it is not recommended to use.

@johnsoncodehk johnsoncodehk marked this pull request as ready for review December 24, 2024 21:22
@johnsoncodehk johnsoncodehk merged commit 8d54167 into master Dec 24, 2024
6 checks passed
@johnsoncodehk johnsoncodehk deleted the asyncComputed branch December 24, 2024 21:22
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.

1 participant