JavaScript Decorators From Scratch

Decorators in Angular


However, decorators are currently not an ES standard, and the process of standardization is taking a long time. It also looks like the standard will be different from the way decorators were implemented previously.

Core Decorators JS

This library comes with decorators such as “@readonly”, “@time”, “@deprecate” and more. You can check out more over here.

Redux Library in React

//Before decorator
class MyApp extends React.Component {
// ...define your main app here
export default connect(mapStateToProps, mapDispatchToProps)(MyApp);
//After decorator
@connect(mapStateToProps, mapDispatchToProps)
export default class MyApp extends React.Component {
// ...define your main app here

Felix Kling’s Stack Overflow answer explains this.

Furthermore, although connect supports the decorator syntax, it has been discouraged by the redux team at the moment. This is mostly because the decorator proposal in stage 2 can accommodate changes in the future.

Author: Shantun Parmar

Leave a Reply

Your email address will not be published.