@decorators on class are still being placed on separate line
See original GitHub issuePrettier 1.15.1 Playground link
--parser typescript
Input:
import { action, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { RouteComponentProps } from 'react-router';
interface CountHandlerProps extends RouteComponentProps<{}> { }
@observer export class CountHandler extends React.Component<CountHandlerProps> {
@observable count = 0;
render() {
const { data } = this;
return (
<div>
Count: {this.count}
<button onClick={this.handleIncreaseClick}>Increase</button>
<button onClick={handleResetClick}>Reset</button>
</div>
);
}
@action handleIncreaseClick = () => this.count++;
@action handleResetClick = () => {
this.count = 0;
}
}
Output:
import { action, observable } from "mobx";
import { observer } from "mobx-react";
import * as React from "react";
import { RouteComponentProps } from "react-router";
interface CountHandlerProps extends RouteComponentProps<{}> {}
@observer
export class CountHandler extends React.Component<CountHandlerProps> {
@observable count = 0;
render() {
const { data } = this;
return (
<div>
Count: {this.count}
<button onClick={this.handleIncreaseClick}>Increase</button>
<button onClick={handleResetClick}>Reset</button>
</div>
);
}
@action handleIncreaseClick = () => this.count++;
@action
handleResetClick = () => {
this.count = 0;
};
}
Expected behavior:
I would expect the @observer
decorator and the second (fixed in 1.15.2) to stay inline as discussed in #4924.@action
decorator
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Python decorators in classes - Stack Overflow
If I have to put decorator calls at the end of the class, then it isn't clear that the functions are being decorated....
Read more >Documentation - Decorators - TypeScript
Decorators provide a way to add both annotations and a meta-programming syntax for class declarations and members. Decorators are a stage 2 proposal...
Read more >Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create and use them.
Read more >Python: Decorators in OOP - Towards Data Science
Decorators are functions (or classes) that provide enhanced ... method inside the Student class, and place our decorator outside the class.
Read more >6. Decorators and Decoration | Advanced - Python Courses eu
Even though it is the same underlying concept, we have two different kinds of decorators in Python: Function decorators; Class decorators.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@desbrowne --> #5423
@svipben We plan to release a patch tomorrow.
Thanks @ikatyang, placing
@observer
inline is pretty standard in the mobx community, for example the official docs: https://mobx.js.org/refguide/observer-component.html