Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[on hold] WIP: Support decorators stage 2 proposal, implements #1352 #1732

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d5d9195
Switched to stage 2 decorator implementation
mweststrate Sep 20, 2018
3d3ee18
First implementation of stage 2 decorators
mweststrate Sep 24, 2018
bc572f0
Fixed unchecked exception in reaction test suite
mweststrate Sep 24, 2018
f9b7f0d
Keep class properties `loose` to support `decorate`
mweststrate Sep 24, 2018
c7990cf
Minor fixes, skipped some tests
mweststrate Sep 24, 2018
ef0f674
Clean up action decorator
mweststrate Sep 24, 2018
f44fc89
Restored tests
mweststrate Sep 24, 2018
006c312
Minor improvements
mweststrate Sep 24, 2018
152805e
Lowered prettier version to fix formatting
mweststrate Sep 24, 2018
afdb00f
Cleaner code path separation for stage2 computed
mweststrate Sep 24, 2018
b4b427c
cleaned up @observable implementation
mweststrate Sep 24, 2018
4503c6e
code cleanup
mweststrate Sep 24, 2018
a5818ba
Some tidy up
mweststrate Sep 24, 2018
3cbcfb5
Found work around for late initialization
mweststrate Sep 25, 2018
1c7093a
Introduced better work-around for lazy observable initialization
mweststrate Sep 25, 2018
1bcb4a9
Disabled perf test
mweststrate Sep 25, 2018
ac3d2ef
Added TODO about using stage2 impl for decorate / extendobservable in…
mweststrate Sep 25, 2018
6092288
Updated Changelog
mweststrate Sep 25, 2018
2ef7347
fixed typo
mweststrate Sep 25, 2018
88c8c3a
Merge branch 'master' into decorators-stage-2
mweststrate Feb 2, 2019
23d245e
Upgraded to Babel 7.3.0
mweststrate Feb 2, 2019
93a81e3
WIP: use hooks from the proposal
mweststrate Feb 2, 2019
9d88fdf
Added codefirst to the sponsors list
mweststrate Feb 4, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# Next Minor

(Jumped minor version of 5 to have the numbers more closely aligned)

MobX now supports 4 different implementations of the decorators proposal:
* TypeScript with the `--experimentalDecorators` compiler flag enabled
* Babel 6, trough the `babel-plugin-transform-decorators-legacy` plugin
* Babel 7, with `@babel/plugin-proposal-decorators` in legacy mode. (Setting: `legacy: true`)
* **🎉NEW🎉** Babel 7, with `@babel/plugin-proposal-decorators` in stage 2 spec mode. (Setting: `legacy: false`)

Because these implementations offer different features and semantics, there are subtle differences in all implementations.
They won't affect 99% of your work, but sometimes there are subtle differences.

These are the changes introduced by the Babel 7 implementation *if* `legacy` is set to `false`:

* The legacy decorators issue where fields were not initialized until the first read are solved.
* The exception is computed properties, running `isComputedProp` on an `@computed` decorated field that was never accessed will incorrectly yield `false`. ([background](https://github.com/tc39/proposal-decorators/issues/153))
* There is a [babel issue](https://github.com/babel/babel/issues/8760), which has been fixed but not released yet, which causes non-decorated fields to be no longer enumerable. This currently breaks utilities like `toJS`, however this is not a MobX issue and should resolve itself with the next Babel release.
* Computed properties become now live on the instance, rather than the prototype, so they become part of the _ownProperties_ of an object. However, they are still not enumerable, so this should make no difference in practice.
* MobX generates non-enumerable utility properties that are all of the form `__mobx-initializer-${propName}`. Those always have the value `undefined` and you can even delete them if they annoy you, but those were introduced to work around some limitations of the current stage2 proposal ([background](https://github.com/tc39/proposal-decorators/issues/153))
* By supporting the stage2 implementation, it is now possible to use `@babel/plugin-proposal-class-properties` in spec mode (that is, with option: `{ "loose": false }`). However, the `spec` mode breaks using the `decorate` utility on class instances, so for now it is recommended to keep using `{ "loose": true }` in your babel configuration
* The value of te `decoratorsBeforeExport` setting of `plugin-proposal-decorators` is technically indifferent to MobX, but it is recommended to set it to `true`, this is in line with the legacy syntax and all current MobX documentation. With `true`, one can write: `@observer export class MyComponent extends React.Component {...`, with `false`, this needs to be rewritten as: `export @observer class MyComponent extends React.Component {...`. ([background](https://github.com/tc39/proposal-decorators/issues/69))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of recommending decoratorsBeforeExport: true you could just say that it is similar to the old behavior but that it could change? Since TC39 hasn't decided yet it would be better not to recommend neither true not false.


In summary: this is the babel config that uses the stage2 decorators implementation:

```json
{
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": false, "decoratorsBeforeExport": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
```

# 4.9.2

* Fixed regression [#1878](https://github.com/mobxjs/mobx/issues/1878), accidental use of `Symbol` breaking Internet Explorer / React Native compatibility.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MobX is proudly sponsored by Mendix, Coinbase, Facebook Open Source, Canva, Algo
<a href="http://auctionfrontier.com/"><img src="docs/auctionfrontier.jpeg" align="center" width="100" title="Auction Frontier" alt="Auction Frontier"></a>
<a href="https://mantro.net/jobs/warlock"><img src="docs/mantro.png" align="center" width="100" title="mantro GmbH" alt="mantro GmbH"></a>
<a href="https://talentplot.com/"><img src="docs/talentplot.png" align="center" width="100" title="talentplot" alt="talentplot"></a>
<a href="https://www.codefirst.co.uk/"><img src="https://mobx.js.org/docs/codefirst.png" align="center" width="100" title="CodeFirst" alt="CodeFirst"/></a>

# Installation

Expand Down
Loading