-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
mobx.decorate doesn't work #1969
Comments
Reproduced the problem - assigned value isn't converted to observable when the "native" (non-transpiled) property initializer is used. class MyClass {
a; // note it doesn't matter where the value is assigned
constructor() {
this.a = [];
this.b = [];
}
}
mobx.decorate(MyClass, { a: mobx.observable, b: mobx.observable })
const i = new MyClass();
console.log(mobx.isObservable(i.a)); // false
console.log(mobx.isObservable(i.b)); // true |
I ran into this issue also, although not using from a cdn. exporting the class immediately fixed my issues. As in, “export class Thing ...” Using a named es export after decorate was the immediate cause, i dont know if that is expected or not, im not sure the es spec knows either |
class members has defineGetter / defineSetter behaviour that being created per instance seems like |
For anyone who is trying to test https://kulshekhar.github.io/ts-jest/user/config/babelConfig It took me a while to arrive at this so it might save someone some time. Basic
@jeremy-coleman this, unfortunately, didn't make any difference in |
Probably better to focus decorators related discussion to #2325. Closing this one. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
1 similar comment
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
I'm not using any compilers. I'm loading MobX from a CDN. The
decorate
method simply doesn't seem to work.I have a:
Steps to reproduce
The "code sandbox" normally used for reproduction does way more than it should, so you'll have to create a couple of files and spin up a static web server to reproduce this.
mobx-issue.js
I only added the timeout because it looks like the decorators are added as "pending", but I don't know what that's supposed to mean. The assertions fail regardless.
Expectations
I expect the above assertions in the script to not fail, but they do.
I also expect the
instance1.list.replace
andinstance2.list.replace
calls to not throw errors, but they do.I suspect the issue is either in the build artifacts, or related to not using Babel/Webpack and other fluff with my source, or some combination of these.
I got as far as understanding that the decorators are applied in some sort of "pending" state. This is
MyClass.prototype.Symbol(mobx pending decorators).list
:I also know that the
decoratorFactory
function in MobX (line 322) will get anundefined
applyImmediately
argument. I'm not sure if this is relevant.Tested with minified and unminified UMD and "module" builds of MobX version 5.9.4 on Chrome 76.0.3799.0
The text was updated successfully, but these errors were encountered: