Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mobx6] @action.bound decorator not binding #2522

Closed
anri-asaturov opened this issue Oct 17, 2020 · 6 comments
Closed

[mobx6] @action.bound decorator not binding #2522

anri-asaturov opened this issue Oct 17, 2020 · 6 comments
Labels

Comments

@anri-asaturov
Copy link

anri-asaturov commented Oct 17, 2020

Intended outcome:

Trying to use @action.bound in a class with makeObservable(this) and reference @observable property of the same class. The solution from #2468 does not work.

class C {
  @observable x!: number; // if assigned here - works

  @action.bound // but not really
  incX() {
    this.x++;
  }

  constructor() {
    // this.x = 0 // if assigned here - works
    makeObservable(this);
    this.x = 0; // if assigned here - breaks
  }
}

Actual outcome:

Action is not getting actually bound.
Surprisingly, initializing property makes action bound properly.

How to reproduce the issue:

https://codesandbox.io/s/distracted-glade-y30yg?file=/src/index.ts

@mweststrate
Copy link
Member

mweststrate commented Oct 17, 2020 via email

@anri-asaturov
Copy link
Author

@mweststrate I did, if you're referring to tsconfig.json: "useDefineForClassFields": true - it is set there in the sandbox.

@anri-asaturov
Copy link
Author

I raised this issue because you asked to do it here #2467 and it's still reproducing in 6.0.1

@mweststrate
Copy link
Member

mweststrate commented Oct 17, 2020

Ah yes, sorry, was reading to quickly, apologies.

This is probably an earlier reported babel bug, it has been fixed already, but it might not yet be available in Parcel / Code Sandbox already. See #2486, babel/babel#12146. Best check first if Babel 7.12 or higher is used behind the scenes.

@anri-asaturov
Copy link
Author

@mweststrate I was just trying to figure out why can't I reproduce it locally, so you're probably right, thank you.

@mweststrate
Copy link
Member

Added it to the docs, since more people will probably stumble on it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants