-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed circular dependency problem with Atoms
- Loading branch information
1 parent
c79f843
commit f758123
Showing
4 changed files
with
50 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f758123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mweststrate Unfortunately, this technique falls apart when compiling to CommonJS, because there's no hoisting of vars or functions (beyond the module boundaries) in CommonJS. 😭
f758123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trusktr Just a little correction. CommonJS has nothing to do with hoisting, that's a feature of ES2015. CommonJS is only about
require
andmodule.exports
in comparison toimport/export
from ESM. However, since the mobx is compiled to ES5 then it indeed does not have any hoisting features. There is alsomobx.es6.js
distribution file. If you use that, hoisting would work and it's in CommonJS format.f758123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trusktr sorry, I don't get what you mean by "this fails". The technique, or using MobX? If this causes a problem, please do open an issue. This was merged over a year ago, so the intent of your comment is unclear to me when posted on a commit :)
f758123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some background, read https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de?source=---------7------------------, and yes, that is specifically designed to solve the problem for commonJS, which, indeed doesn't hoist beyond module boundaries :).