mobx 6.1.8 → 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +57 -5
  2. package/README.md +2 -1
  3. package/dist/api/annotation.d.ts +6 -12
  4. package/dist/api/flow.d.ts +1 -0
  5. package/dist/api/object-api.d.ts +2 -0
  6. package/dist/errors.d.ts +2 -0
  7. package/dist/internal.d.ts +1 -0
  8. package/dist/mobx.cjs.development.js +322 -310
  9. package/dist/mobx.cjs.development.js.map +1 -1
  10. package/dist/mobx.cjs.production.min.js +1 -1
  11. package/dist/mobx.cjs.production.min.js.map +1 -1
  12. package/dist/mobx.d.ts +1 -1
  13. package/dist/mobx.esm.development.js +320 -311
  14. package/dist/mobx.esm.development.js.map +1 -1
  15. package/dist/mobx.esm.js +320 -311
  16. package/dist/mobx.esm.js.map +1 -1
  17. package/dist/mobx.esm.production.min.js +1 -1
  18. package/dist/mobx.esm.production.min.js.map +1 -1
  19. package/dist/mobx.umd.development.js +322 -310
  20. package/dist/mobx.umd.development.js.map +1 -1
  21. package/dist/mobx.umd.production.min.js +1 -1
  22. package/dist/mobx.umd.production.min.js.map +1 -1
  23. package/dist/types/actionannotation.d.ts +7 -1
  24. package/dist/types/autoannotation.d.ts +3 -0
  25. package/dist/types/observableobject.d.ts +4 -7
  26. package/package.json +1 -1
  27. package/src/api/annotation.ts +13 -42
  28. package/src/api/flow.ts +6 -1
  29. package/src/api/makeObservable.ts +25 -34
  30. package/src/api/object-api.ts +14 -0
  31. package/src/api/observable.ts +3 -8
  32. package/src/api/tojs.ts +10 -7
  33. package/src/core/observable.ts +7 -6
  34. package/src/errors.ts +14 -1
  35. package/src/internal.ts +1 -0
  36. package/src/mobx.ts +4 -0
  37. package/src/types/actionannotation.ts +27 -51
  38. package/src/types/autoannotation.ts +107 -0
  39. package/src/types/computedannotation.ts +7 -37
  40. package/src/types/dynamicobject.ts +1 -1
  41. package/src/types/flowannotation.ts +31 -42
  42. package/src/types/modifiers.ts +13 -2
  43. package/src/types/observableannotation.ts +7 -34
  44. package/src/types/observableobject.ts +34 -63
  45. package/src/types/overrideannotation.ts +4 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # mobx
2
2
 
3
+ ## 6.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`4011b378`](https://github.com/mobxjs/mobx/commit/4011b3789d57e3dab0b85a835fe2979033133ce9) [#2949](https://github.com/mobxjs/mobx/pull/2949) Thanks [@urugator](https://github.com/urugator)! - fix #2948: flow ignores `autoBind` option
8
+
9
+ ## 6.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`d678ebd7`](https://github.com/mobxjs/mobx/commit/d678ebd7e54efb3aeae4541f87f5bcf93a623ec6) [#2944](https://github.com/mobxjs/mobx/pull/2944) Thanks [@urugator](https://github.com/urugator)! - Fix [#2941](https://github.com/mobxjs/mobx/issues/2941) - flow.bound replaces method on proto with bound function
14
+
15
+ ## 6.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [`035bf409`](https://github.com/mobxjs/mobx/commit/035bf4096dd72d296af1fc25304adaade73cc7eb) [#2906](https://github.com/mobxjs/mobx/pull/2906) Thanks [@urugator](https://github.com/urugator)! - Provide `flow.bound` annotation/decorator
20
+
21
+ ### Patch Changes
22
+
23
+ - [`3dedb4d4`](https://github.com/mobxjs/mobx/commit/3dedb4d4b5376f3991183923838da942a9a81506) [#2904](https://github.com/mobxjs/mobx/pull/2904) Thanks [@ahoisl](https://github.com/ahoisl)! - Make toJS work with computed value props
24
+
25
+ ## 6.2.0
26
+
27
+ ### Minor Changes
28
+
29
+ - [`bc8db3df`](https://github.com/mobxjs/mobx/commit/bc8db3df9405034999f8feb8c95ba8045c7ae008) [#2779](https://github.com/mobxjs/mobx/pull/2779) Thanks [@urugator](https://github.com/urugator)! - In mobx5 all own properties were by default observable regardless of their value. Since mobx6 we treat functional properties as `action`s or to be precise `autoAction`s. `autoAction` provides `action`'s benefits to your functions, without the need to explicitely annotate them as `actions`.
30
+ We think this is useful, but as a consequence, such properties are no longer `observable` and therefore non-writable and also non-enumerable. This turned out to be suprising and inconvinient to some users:
31
+ https://github.com/mobxjs/mobx/discussions/2760
32
+ https://github.com/mobxjs/mobx/discussions/2586
33
+ https://github.com/mobxjs/mobx/issues/2835
34
+ https://github.com/mobxjs/mobx/issues/2629
35
+ https://github.com/mobxjs/mobx/issues/2551
36
+ https://github.com/mobxjs/mobx/issues/2637
37
+ So we decided to change it: All _own_ props _including functions_ are `observable` (enumerable, writable) as in v5, but additionally all functions that become part of deeply observable structure are by default converted to `autoAction`/`flow`.
38
+ Note that `deep` option affects this conversion in the same way as it affects conversion of other values (object/array/map/set).
39
+
40
+ - by default all functions are converted to `autoAction`s/`flow`s
41
+ - by default all originally _own_ props are now observable and enumerable (as in pre v6)
42
+ - `deep: false` ignores _all_ property values (including functions that would be previously converted to `autoAction`/`flow`)
43
+ - by default _lone_ setters are converted to `action`s
44
+
45
+ ### Patch Changes
46
+
47
+ - [`16cab8b1`](https://github.com/mobxjs/mobx/commit/16cab8b14cf4a0d995d3f367123abfab5aed8326) [#2806](https://github.com/mobxjs/mobx/pull/2806) Thanks [@urugator](https://github.com/urugator)! - Annotations refactor - reduced code duplication
48
+
49
+ * [`6b324edc`](https://github.com/mobxjs/mobx/commit/6b324edc69e7e9041a01e20d2e86f424046f3e25) [#2873](https://github.com/mobxjs/mobx/pull/2873) Thanks [@urugator](https://github.com/urugator)! - Fix [#2871](https://github.com/mobxjs/mobx/issues/2871): `toJS` throws with `configure({ useProxies: "ifavailable" })`
50
+
51
+ - [`b5141883`](https://github.com/mobxjs/mobx/commit/b5141883434cba86b257d68a7badff5038c14296) [#2872](https://github.com/mobxjs/mobx/pull/2872) Thanks [@urugator](https://github.com/urugator)! - Fix [#2859](https://github.com/mobxjs/mobx/issues/2859): Trace log only if derivation is actually about to re-run
52
+
53
+ * [`0945c265`](https://github.com/mobxjs/mobx/commit/0945c26513057457e1534a80558a3eb98487dc96) [#2840](https://github.com/mobxjs/mobx/pull/2840) Thanks [@iChenLei](https://github.com/iChenLei)! - export IComputedFactory typescript type definition
54
+
3
55
  ## 6.1.8
4
56
 
5
57
  ### Patch Changes
@@ -145,12 +197,12 @@ Support the ongoing maintenance at: https://opencollective.com/mobx
145
197
 
146
198
  ### New features
147
199
 
148
- - [`makeObservable(target, annotations)`](./docs/observable-state.md#makeobservable) is now the recommended way to make objects with a fixed shape observable, such as classes.
149
- - [`makeAutoObservable(target)`](./docs/observable-state.md#makeautoobservable) will automatically determine the annotations used by `makeObservable`. Methods will be marked as 'autoAction', so that they can be used both from a computed value or as standalone method.
150
- - MobX 6 can be used in both modern environments, and environments that don't support Proxy. So both MobX 4 and 5 users can upgrade to 6. See [proxy support](./docs/configuration.md#proxy-support) for more details.
200
+ - [`makeObservable(target, annotations)`](../../docs/observable-state.md#makeobservable) is now the recommended way to make objects with a fixed shape observable, such as classes.
201
+ - [`makeAutoObservable(target)`](../../docs/observable-state.md#makeautoobservable) will automatically determine the annotations used by `makeObservable`. Methods will be marked as 'autoAction', so that they can be used both from a computed value or as standalone method.
202
+ - MobX 6 can be used in both modern environments, and environments that don't support Proxy. So both MobX 4 and 5 users can upgrade to 6. See [proxy support](../../docs/configuration.md#proxy-support) for more details.
151
203
  - `observable.array` now supports `{ proxy: false }` as option.
152
204
  - `reaction`'s effect function now receives the previous value seen by the reaction as second argument.
153
- - `flow` can now be used as annotation as well. You might need `flowResult` in case you use TypeScript to extract the correct result type. [details](./docs/actions.md#using-flow-instead-of-async--await-).
205
+ - `flow` can now be used as annotation as well. You might need `flowResult` in case you use TypeScript to extract the correct result type. [details](../../docs/actions.md#using-flow-instead-of-async--await-).
154
206
 
155
207
  ### Breaking changes
156
208
 
@@ -158,7 +210,7 @@ Support the ongoing maintenance at: https://opencollective.com/mobx
158
210
 
159
211
  - The `decorate` API has been removed, and needs to be replaced by `makeObservable` in the constructor of the targeted class. It accepts the same arguments. The `mobx-undecorate` can transform this automatically.
160
212
  - When using `extendObservable` / `observable`, fields that contained functions used to be turned into observables. This is no longer the case, they will be converted into `autoActions`.
161
- - [Strict mode](./docs/configuration.md#enforceactions) for actions is now enabled by default in `observed` mode.
213
+ - [Strict mode](../../docs/configuration.md#enforceactions) for actions is now enabled by default in `observed` mode.
162
214
  - `toJS` no longer takes any options. It no longer converts Maps and Sets to plain data structures. Generic, flexible serialization of data structures is out of scope for the MobX project, and writing custom serialization methods is a much more scalable approach to serialization (tip: leverage `computed`s to define how class instances should be serialized).
163
215
  - The methods `intercept` and `observe` are no longer exposed on observable arrays, maps and boxed observables. Import them as utility from mobx instead: `import { observe, intercept } from "mobx"`, and pass the collection as first argument: `observer(collection, callback)`. Note that we still recommend to avoid these APIs.
164
216
  - `observableMap.toPOJO()`, `observableMap.toJS()` have been dropped. Use `new Map(observableMap)` instead if you want to convert an observable map to a plain Map shallowly.
package/README.md CHANGED
@@ -28,10 +28,11 @@ MobX is made possible by the generosity of the sponsors below, and many other [i
28
28
 
29
29
  **🥈Silver sponsors (\$100+ pm):**<br/>
30
30
  <a href="https://www.codefirst.co.uk/"><img src="https://mobx.js.org/assets/codefirst.png" align="center" width="100" title="CodeFirst" alt="CodeFirst"/></a>
31
- <a href="https://www.dcslsoftware.com/"><img src="https://mobx.js.org/assets/dcsl.png" align="center" width="100" title="DCSL Software" alt="DCSL Software"/></a>
31
+ <a href="https://www.dcsl.com/"><img src="https://mobx.js.org/assets/dcsl.png" align="center" width="100" title="DCSL Guidesmiths" alt="DCSL Guidesmiths"/></a>
32
32
  <a href="https://www.bugsnag.com/platforms/react-error-reporting?utm_source=MobX&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term=20190913"><img src="https://mobx.js.org/assets/bugsnag.jpg" align="center" width="100" title="Bugsnag" alt="Bugsnag"/></a>
33
33
  <a href="https://curology.com/blog/tech"><img src="https://mobx.js.org/assets/curology.png" align="center" width="100" title="Curology" alt="Curology"/></a>
34
34
  <a href="https://modulz.app/"><img src="https://mobx.js.org/assets/modulz.png" align="center" width="100" title="Modulz" alt="Modulz"/></a>
35
+ <a href="https://space307.com/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/space307.png" align="center" width="100" title="Space307" alt="Space307"/></a>
35
36
 
36
37
  **🥉Bronze sponsors (\$500+ total contributions):**<br/>
37
38
  <a href="https://mantro.net/jobs/warlock"><img src="https://mobx.js.org/assets/mantro.png" align="center" width="100" title="mantro GmbH" alt="mantro GmbH"></a>
@@ -1,7 +1,12 @@
1
1
  import { ObservableObjectAdministration } from "../internal";
2
+ export declare const enum MakeResult {
3
+ Cancel = 0,
4
+ Break = 1,
5
+ Continue = 2
6
+ }
2
7
  export declare type Annotation = {
3
8
  annotationType_: string;
4
- make_(adm: ObservableObjectAdministration, key: PropertyKey): void;
9
+ make_(adm: ObservableObjectAdministration, key: PropertyKey, descriptor: PropertyDescriptor, source: object): MakeResult;
5
10
  extend_(adm: ObservableObjectAdministration, key: PropertyKey, descriptor: PropertyDescriptor, proxyTrap: boolean): boolean | null;
6
11
  options_?: any;
7
12
  };
@@ -9,16 +14,5 @@ export declare type AnnotationMapEntry = Annotation | true | false;
9
14
  export declare type AnnotationsMap<T, AdditionalFields extends PropertyKey> = {
10
15
  [P in Exclude<keyof T, "toString">]?: AnnotationMapEntry;
11
16
  } & Record<AdditionalFields, AnnotationMapEntry>;
12
- /**
13
- * Infers the best fitting annotation from property descriptor or false if the field shoudn't be annotated
14
- * - getter(+setter) -> computed
15
- * - setter w/o getter -> false (ignore)
16
- * - flow -> false (ignore)
17
- * - generator -> flow
18
- * - action -> false (ignore)
19
- * - function -> action (optionally bound)
20
- * - other -> defaultAnnotation
21
- */
22
- export declare function inferAnnotationFromDescriptor(desc: PropertyDescriptor, defaultAnnotation: Annotation, autoBind: boolean): Annotation | false;
23
17
  export declare function isAnnotation(thing: any): boolean;
24
18
  export declare function isAnnotationMapEntry(thing: any): boolean;
@@ -10,6 +10,7 @@ export declare type CancellablePromise<T> = Promise<T> & {
10
10
  };
11
11
  interface Flow extends Annotation, PropertyDecorator {
12
12
  <R, Args extends any[]>(generator: (...args: Args) => Generator<any, R, any> | AsyncGenerator<any, R, any>): (...args: Args) => CancellablePromise<R>;
13
+ bound: Annotation & PropertyDecorator;
13
14
  }
14
15
  export declare const flow: Flow;
15
16
  export declare function flowResult<T>(result: T): T extends Generator<any, infer R, any> ? CancellablePromise<R> : T extends CancellablePromise<any> ? T : never;
@@ -32,3 +32,5 @@ export declare function has<T extends Object>(obj: T, key: string): boolean;
32
32
  export declare function get<K, V>(obj: ObservableMap<K, V>, key: K): V | undefined;
33
33
  export declare function get<T>(obj: IObservableArray<T>, index: number): T | undefined;
34
34
  export declare function get<T extends Object>(obj: T, key: string): any;
35
+ export declare function apiDefineProperty(obj: Object, key: PropertyKey, descriptor: PropertyDescriptor): any;
36
+ export declare function apiOwnKeys(obj: Object): any;
package/dist/errors.d.ts CHANGED
@@ -34,6 +34,8 @@ declare const niceErrors: {
34
34
  readonly 35: "There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`";
35
35
  readonly 36: "isolateGlobalState should be called before MobX is running any reactions";
36
36
  readonly 37: (method: any) => string;
37
+ readonly 38: "'ownKeys()' can only be used on observable objects";
38
+ readonly 39: "'defineProperty()' can only be used on observable objects";
37
39
  };
38
40
  declare const errors: typeof niceErrors;
39
41
  export declare function die(error: string | keyof typeof errors, ...args: any[]): never;
@@ -10,6 +10,7 @@ export * from "./types/actionannotation";
10
10
  export * from "./types/flowannotation";
11
11
  export * from "./types/computedannotation";
12
12
  export * from "./types/observableannotation";
13
+ export * from "./types/autoannotation";
13
14
  export * from "./api/observable";
14
15
  export * from "./api/computed";
15
16
  export * from "./core/action";