Comments (5)
I think you can implement the @catch decorator in the current proposal by using a decorator which replaces the value of the element's property descriptor with another function which does the catching. You could also use try/catch in your async function, of course. For bound methods, this repository contains source for an @bound decorator, or you could use a field declaration with an arrow function.
from proposal-decorators.
Could your "catch" decorator not return function (...args) { return original.call(this, ...args).catch(this.errorHandler); }
, without any need for ::
?
iow, it'd be like:
class {
@catch(this.errorHandler)
async handler(e) {
…
}
errorHandler(e) {
this.e = e;
console.error(e);
}
from proposal-decorators.
ah, after updating my comment to include a code sample, you're asking primarily about the this.errorHandler
- and it's a bit awkward to do @catch(function (...args) { return this.errorHandler(...args); })
.
from proposal-decorators.
If you’re an async function or a promise and your invoker is not, ie. the invocation does not have await, then you are often going to need an onReject function
The onReject functions are typically bound or static, and a class method or a function value provided to the constructor
error handler functions are typically shared by multiple or even all async functions and promises
from proposal-decorators.
Please reopen this issue if you have any concerns with this response. As far as I can tell, your requirements are met by the current proposal.
from proposal-decorators.
Related Issues (20)
- Stage 3 allow decorators to generate PJOs HOT 1
- Timeline / proposal for extensions? HOT 8
- Using accessors makes code less clean and readable HOT 21
- Counterintuative ordering when using `accessor` in combination with `init` methods HOT 37
- Can't dynamically set private field in initializer HOT 17
- Context.private doesn't seem to support group accessor HOT 1
- Support changing the backing field used by auto-accessors HOT 2
- Towards stage 4 HOT 14
- Field and Accessor initializers should run after the field/accessor has been defined HOT 12
- Stage 3 cannot access the class for static method decorator HOT 3
- Idea: syntax for decorator composition. HOT 3
- How to exclude methods from class decorator HOT 2
- Add target class to the context HOT 6
- Order of execution HOT 3
- It isn't clear when `addInitializer` functions are called on class decorator HOT 2
- feature request (separate proposal?): `context.addPostInitializer()` HOT 18
- Readme text and types are outdated against actual spec HOT 2
- Field decorator initializer should support configurable field HOT 8
- Was there a purpose for non-lexical ordering of decorator applications? HOT 2
- Write upgrade guide for previous iterations to Stage 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-decorators.