You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In many cases, I need to catch the error in a button to show an alert or update some state. It's tedious to always try and catch, what if we could do this:
AsyncButton{tryawaitlongOperation()}label:{Label("Long Operation",systemImage:"clock")}error:{errorin
// Do somethig with error
}
Sure. If that's easier to implement than a closure, it's equally elegant I think.
It's not easier to implement, but I find the pattern better suited for an optional closure than making that a standard stuff that would be for all the init() overrides out there
I see an advantage with the modifier, is that you can deal with the error of multiple buttons at the same time:
Group{AsyncButton{...}label:{...}AsyncButton{...}label:{...}AsyncButton{...}label:{...}}.onButtonError{errorin
// Do something with the error
print(error)}
Activity
Dean151 commentedon Dec 31, 2024
Hi @milanvarady!
Would a modifier work?
milanvarady commentedon Dec 31, 2024
Sure. If that's easier to implement than a closure, it's equally elegant I think.
Dean151 commentedon Dec 31, 2024
It's not easier to implement, but I find the pattern better suited for an optional closure than making that a standard stuff that would be for all the init() overrides out there
Dean151 commentedon Jan 12, 2025
Rethinking about it, I wonder what you have against the currently supported format:
Catching to re-throw is a pretty common pattern
milanvarady commentedon Jan 12, 2025
It's just that almost all of my async functions are throwing and I thought it would be cleaner to do it the way I suggested.
Dean151 commentedon Jan 12, 2025
I see an advantage with the modifier, is that you can deal with the error of multiple buttons at the same time:
I'll implement that for version 0.6.0
milanvarady commentedon Jan 12, 2025
Thats actually pretty nice. Thanks.
feat: added onButtonError modifier