Comments (6)
Bummer, native transpiles defaults like this:
function*foo(a=5) {};
// =>
function foo() {
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
return function* () {}();
}
You may try to report it as a bug in native. Maybe it should produce:
function*foo() {
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
return yield * function* () {}();
}
from mobx.
@urugator
Hmmm. But do the two options you provided behave the same way?
- The first (current native) transpiling result would assign the default parameter value during the generator function call.
- For the second, it would be assigned on the first
.next()
call.
Considering the fact that a default value can be not only a constant, I assume the current transpiling result is probably correct.
At this point, I think flow
should be removed entirely from the makeAutoObservable
magic and used explicitly only.
from mobx.
What if MobX could warn a developer that the environment it works in can make generators undetectable by makeAutoObservable
, and hint to wrap them in flow explicitly?
// isGenerator from mobx source code
function isGenerator(obj) {
...
}
function isGeneratorsDetectable() {
function* generatorWithDefaultParameter(arg = 0) {
return arg;
}
if (isGenerator(generatorWithDefaultParameter)) {
return true;
}
return false;
}
Maybe It can be checked during the first makeAutoObservable call for the development environment?
from mobx.
But do the two options you provided behave the same way?
As you pointed out, they do not.
At this point, I think flow should be removed entirely from the makeAutoObservable magic and used explicitly only.
I don't have a strong opinion about it, but it would be a BC, so not much we can do about it atm.
make generators undetectable by makeAutoObservabl
You would have to consume mobx distribution that isn't compiled (contains generator syntax) and compile it with your compiler.
I don't know if that's the case here, but generally it's not I think.
I think we could start with adding a warning to the documentation (that there is this specific problem on native and therefore we suggest using flow explicitely). PR welcome.
from mobx.
@urugator
Thank you for the answers! I'll create the documentation PR later this week.
Another option that comes to my mind is the following:
- Make makeAutoObservable wrapping generators in
flow
configurable, set enabled by default. - Check for generator detectability on the top execution level (where Symbol, Map, and Set are checked for availability).
- If the check fails, warn the developer and suggest disabling the automatic
flow
wrapping, promoting explicitflow
use for the codebase.
The motivation is that now there is no obvious way to protect a developer (or a team) from the issue, and a warning can be at least something that might help here. Maybe this is overkill, though.
I would be happy to implement that!
from mobx.
@pasha-iwanov the problem is that step 2 generally doesn't work in libraries; because bundlers consume already down-compiled code, so it'd just check that we configured OUR compiler in this repo correctly, but not whether YOUR code is compiled correctly. This is also why we can't detect wrongly non standard configurations for class compilation etc.
However, if you could add a PR explaining how users could add a top-level check to their code that would be helpful for people running into this in the future. Thanks!
from mobx.
Related Issues (20)
- Peer dependency issue for [email protected] HOT 4
- Migration from Mobx 4 > 6 HOT 6
- `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 5
- 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
- mobx-react-lite does not specify `react-dom` nor `react-native` as it's peer dependencies
- Reaction is not triggering When listening to a local observable.
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.