question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@decorators on class are still being placed on separate line

See original GitHub issue

Prettier 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 @action decorator(fixed in 1.15.2) to stay inline as discussed in #4924.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ikatyangcommented, Nov 12, 2018

@desbrowne --> #5423

@svipben We plan to release a patch tomorrow.

1reaction
desbrownecommented, Nov 7, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found