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

Component Events #311

Open
Jake13f opened this issue Apr 29, 2021 · 3 comments
Open

Component Events #311

Jake13f opened this issue Apr 29, 2021 · 3 comments

Comments

@Jake13f
Copy link

Jake13f commented Apr 29, 2021

What problem is this solving

Currently there is no way without using a watcher to invoke a function upon promise resolution or rejection. In the app I'm working on we use notifications when something goes wrong. I can't invoke the notification service from the template.

Proposed solution

Emit @resolved and @rejected events from the promised component when the promise is resolved or rejected.

Example Usage

<promised :promise="makeApiCall()" @rejected="hdlRejected">
   <!-- Some UI Code here -->
</promised
@LifeIsStrange
Copy link

I think this could be very useful for observability and better error handling (such as tentatively recovering from errors)

@darrylnoakes
Copy link

darrylnoakes commented Oct 6, 2021

Your solution looks good, and I believe it would be the best solution in most cases.

As a workaround, would getting the Promise in the script and using it directly work? This doesn't require watchers.

E.g. for the case you outlined above:

const apiCallPromise = ref(makeApiCall())

apiCallPromise.value.catch(
  (reason) => hdlRejected(reason)
)
<promised :promise="apiCallPromise">
   <!-- Some UI Code here -->
</promised

AbrahemAlhofe added a commit to AbrahemAlhofe/vue-promised that referenced this issue Jun 13, 2022
    Promised fires 'resolved' event when the promise is resolved,
    fires 'rejected' event when the promise is rejected and
    fires 'pending' event when pending delay time is elapsed.

close posva#311
@reksc
Copy link

reksc commented Apr 11, 2023

This is exactly my use-case.

The workaround proposed by @darrylnoakes is on point (thanks), but the proposed API is obviously more elegant and clean.

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

No branches or pull requests

4 participants