mobxjs / mobx-angular

The MobX connector for Angular.
MIT License
483 stars 59 forks source link

mobx-angular 2.1.1 not compatible with mobx 4.0.0 ? #66

Closed KSSLR closed 6 years ago

KSSLR commented 6 years ago

In the mobx-autorun.directive.ts, autoDetect(view) uses mobx autorun with a wrong signature:

this.dispose = autorun( autorunName, () => view['detectChanges']() );

=> autorun(string, function)

but the mobx API expects:

autorun(fn, options?) (https://github.com/mobxjs/mobx/blob/master/CHANGELOG.md, https://github.com/mobxjs/mobx/blob/master/src/api/autorun.ts)

and fails at runtime:

function autorun(view, opts) { if (opts === void 0) { opts = EMPTY_OBJECT; } if (process.env.NODE_ENV !== "production") { invariant(typeof view === "function", "Autorun expects a function as first argument"); invariant(isAction(view) === false, "Autorun does not accept actions since actions are untrackable"); }

as view is not of type "function"

Important!

In case you are reporting a bug, or requesting help, please reproduce it in a GIT repo or fork this online template: https://stackblitz.com/edit/angular-usygae?file=app%2Fapp.component.html

If you are unable to reproduce, please:

Thank you and happy programming

faramos commented 6 years ago

It seems not.

Look at line 39 in: https://github.com/mobxjs/mobx-angular/blob/master/lib/directives/mobx-autorun.directive.ts

autorun needs to be migrated according to this guide: https://github.com/mobxjs/mobx/wiki/Migrating-from-mobx-3-to-mobx-4

autorun(name, fn) -> autorun(fn, { name: name })

adamkleingit commented 6 years ago

Fixed in 3.0.1 - can you verify?

KSSLR commented 6 years ago

Works on my side, thank you.