Installation
- Yarn
- npm
yarn add mobx-keystone
npm install --save mobx-keystone
This library requires a more or less modern JavaScript environment to work, namely one with support for:
- MobX 6, 5, or 4 (with its gotchas)
- Proxies
- Symbols
- WeakMap/WeakSet
In other words, it should work on mostly anything except it won't work in Internet Explorer.
If you are using TypeScript, then version 4.2.0+ is recommended, though it might work with older versions.
Transpiler configuration
This library uses JavaScript decorators and class properties which are supported via the following transpiler configurations:
- TypeScript Compiler
- Babel
- SWC
tsconfig.json
{
// ...
"compilerOptions": {
// ...
"experimentalDecorators": true,
// MobX 5/6
"useDefineForClassFields": true
// MobX 4
"useDefineForClassFields": false
}
}
babel.config.json
{
"presets": [
// ...
// If you use TypeScript
["@babel/preset-typescript", { "allowDeclareFields": true }]
],
"plugins": [
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
// MobX 5/6
["@babel/plugin-proposal-class-properties"]
// MobX 4
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
.swcrc
{
"jsc": {
"parser": {
"syntax": "typescript", // "ecmascript" if you use JavaScript
"decorators": true
},
"transform": {
// Optional if you use TypeScript
// Required if you use JavaScript
"legacyDecorator": true
},
// MobX 5/6
"loose": false
// MobX 4
"loose": true
}
}