Comments (6)
It looks correct. You've added the makeObservable(this)
to the constructor and you're basically done.
mobx-undecorate
is just a tool so you don't have to do this by hand, but it does the same thing.
It's not something you call from the code, you call it from command line, it takes your .js/.ts files and modifies them.
Eg you have 180 classes, you either add makeObservable(this)
to 180 constructors by hand or you run mobx-undecorate
and it does it for you.
from mobx.
at one place, like so?
Yes this configuration is global. Typically you would put it somewhere at the beginning (index.js/main.js). Technically you can call it anytime you want and it just changes the current configuration, so it's respected by any code/calls that follows the configure
call.
Is it before calling a super() or after?
Try to place it before, you will get a JS syntax error.
where should I put the calling of makeObservable(this);
makeObservable(this)
makes existing fields observable. Meaning you have to place it after all fields are defined and before anything that relies on obserability:
class A {
a = 'a'
constructor() {
this.b = 'introducing new field inside a constructor'; // Since you use field initializers + decorators, you don't have to worry about this
makeObservable(this, { a: observable, b: observable });
// autorun/reaction/observe/intercept etc must be after
autorun(() => console.log(this.a, this.b))
}
}
mobx-undecorate codemod
It's a CLI tool that transforms your source code like this:
// original code
class A {
@observable
x = 0
}
// with --keepDecorators option
class A {
@observable
x = 0
constructor() {
makeObservable(this)
}
}
// without --keepDecorators option
class A {
x = 0
constructor() {
makeObservable(this, { x: observable })
}
}
from mobx.
@urugator Thanks for quick reply. I will try to apply all your recommendations today, to see if it helps.
Is it before calling a super() or after?
Try to place it before, you will get a JS syntax error.
is that a recommendation, or are you encouraging me to try it out so I can see the error?
One more thing, I am not sure, where shoudl I put this line of code: ["@babel/plugin-proposal-class-properties", { "loose": false }]
We use craco instead of webpack and there are no signs of babel in our porject,m except peer dependecies. Shall I ignore that settings or do I have to write it somewhere? If so, where should I put it.
Many thanks
from mobx.
encouraging me to try it out so I can see the error?
https://craco.js.org/docs/configuration/babel/
from mobx.
@urugator So this piece of code is not correct?
export default class EditBundleViewModel extends ScreenBase {
busyWatcher = new BusyWatcher();
@observable searchId = 0;
@observable searchText = "";
@observable categories: Category[] = [];
@observable upsells: Item[] = [];
@observable selected: Item[] = [];
@observable serverValidationErrors?: InvalidFields[];
@observable itemsInBundle: OfferItemDto[] = [];
@observable itemsInBundleExpanded: boolean[] = [];
@observable itemsInAdditionalBundle: Item[] = [];
@observable additionalBundleExpandedState: boolean[] = [];
@observable fetchingItems = false;
@observable fetchingUpsells = true;
@observable deletableItems: ProductItemDto[] = [];
@observable showNotSortedCategory = true;
constructor(
public context: OfferContext,
public defaultExpanded: boolean,
public localization: ILocalizationService,
public dialogService: ConfirmDialogService,
private otnaWiseporterRepository: OtnaWiseporterRepository,
private otnaOfferItemsRepository: OtnaOfferItemsRepository,
private editBundleService: EditBundleService,
private userContext: UserContext,
private notificationService: INotificationService
) {
super();
makeObservable(this);
}
and does the order matter? Like do I have to place makeObservable(this) frist and then call the mobx-undecorate?
from mobx.
cool, looks like I successfully updated our app, Thanks for your support
from mobx.
Related Issues (20)
- `StubArray` workaround is incompatible with terser's `unsafe_arrows` option HOT 4
- mobx-react-lite component wrapped in `observer` renders twice in latest Next.js HOT 3
- Peer dependency issue for [email protected] HOT 4
- `trackDerivedFunction` pre-allocates memory for new deps array too aggressively HOT 1
- Invalid/extra warning in observable.box(array)
- Recommended pattern `MyComp = observer(function MyComp() {...})` leads to subtle bug
- Storing a Lit template in a mobx store does not work HOT 3
- Cannot update past `6.10.0` HOT 1
- Supporting of new Set methods in observable Sets HOT 3
- [feature] Investigate running MobX on top of signals standard / polyfill HOT 1
- [eslint-plugin-mobx] ESLint v9 Support
- `isolateGlobalState: true` can cause conflicts that prevent observable registration
- [mobx-react] `Maximum update depth exceeded` error since `mobx-react@8` HOT 2
- makeAutoObservable can't detect a generator after adding a default parameter value HOT 6
- Incompatible with React Forget compiler HOT 3
- [eslint-plugin-mobx] `mobx/exhaustive-make-observable` autofix behavior should be inversed HOT 4
- Converting functions to actions (autoActions?) in deep enhancer leads to bugs HOT 5
- @action decorators on fields do not convert the field value into action HOT 8
- New computed decorator does not apply action to setter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobx.