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

Model, created in itself static method, doesn't work properly when using legacy decorators transpiled by babel #173

Open
Amareis opened this issue Aug 11, 2020 · 10 comments
Labels
✌ duplicate This issue or pull request already exists

Comments

@Amareis
Copy link

Amareis commented Aug 11, 2020

https://codesandbox.io/s/mobx-keystone-static-method-problem-4thb2?file=/src/index.tsx

import { Model, tProp, model } from "mobx-keystone";

@model("BuggyModel")
class BuggyModel extends Model({
  value: tProp("1")
}) {
  static foo() {
    return new BuggyModel({});
  }
}

const a = BuggyModel.foo();
a.value = null as any; //don't throws!
console.log(a); //there is no modelInitializedSymbol in instance

const b = new BuggyModel({})
b.value = null as any; //throws, ok

I think it's coupled with babel, because I cannot reproduce it in pure ts tests. Possible related #18 #92

@xaviergonz
Copy link
Owner

I think it is this babel decorator plugin bug: babel/babel#11131

@xaviergonz
Copy link
Owner

Also related: #122

@Amareis
Copy link
Author

Amareis commented Aug 12, 2020

Yep, definitely it's babel bug. Currently i use external method and assign it into static property

static foo = foo

Can we fix this babel bug? I'll try to look into this.

@xaviergonz xaviergonz added the ✌ duplicate This issue or pull request already exists label Aug 16, 2020
@xaviergonz
Copy link
Owner

If you were to fix the babel plugin that'd be awesome :) Not much that can be done on the mobx-keystone repo sadly

@Amareis
Copy link
Author

Amareis commented Aug 25, 2020

Uh-oh, so I fixed plugin, but not pushed it yet.

@Amareis
Copy link
Author

Amareis commented Aug 25, 2020

babel/babel#12007

@xaviergonz
Copy link
Owner

That's awesome! Let's hope it gets merged soon 👍

@vojto
Copy link

vojto commented Jul 8, 2022

Workarounds in that issue aren't very appealing. I think we'll just avoid static methods for now.

@samskiter
Copy link

womp womp - is this still an issue?

@xaviergonz
Copy link
Owner

It never got fixed by babel, so yes. I don't know if it happens with the new (non legacy) decorators though.

@xaviergonz xaviergonz changed the title Model, created in itself static method, doesn't work properly Model, created in itself static method, doesn't work properly when using legacy decorators transpiled by babel Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✌ duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants