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

Signal-based automatic async function #19

Merged
merged 4 commits into from
Apr 3, 2024
Merged

Conversation

NullVoxPopuli
Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli commented Apr 3, 2024

import { Signal } from 'signal-polyfill';
import { signalFunction } from 'signal-utils/async-function';

const url = new Signal.State('...');
const signalResponse = signalFunction(async () => {
  const response = await fetch(url.get()); // entangles with `url`
  // after an away, you've detatched from the signal-auto-tracking
  return response.json(); 
});

// output: true
// after the fetch finishes
// output: false
<template>
  <output>{{signalResponse.isLoading}}</output>
</template>

the signalResponse object has familiar properties on it:

  • value
  • error
  • state
  • isResolved
  • isPending
  • isRejected

@NullVoxPopuli NullVoxPopuli added the enhancement New feature or request label Apr 3, 2024
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review April 3, 2024 21:19
@NullVoxPopuli NullVoxPopuli merged commit a2da980 into main Apr 3, 2024
3 checks passed
@github-actions github-actions bot mentioned this pull request Apr 3, 2024
@NullVoxPopuli NullVoxPopuli deleted the async-function branch April 3, 2024 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant