mobx 5.8.0 → 5.9.0
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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +0 -0
- package/README.md +8 -8
- package/lib/api/become-observed.d.ts +3 -3
- package/lib/api/flow.d.ts +8 -5
- package/lib/api/intercept-read.d.ts +2 -1
- package/lib/api/intercept.d.ts +2 -1
- package/lib/api/object-api.d.ts +6 -1
- package/lib/api/observable.d.ts +3 -1
- package/lib/api/observe.d.ts +2 -1
- package/lib/core/globalstate.d.ts +1 -0
- package/lib/internal.d.ts +1 -0
- package/lib/mobx.d.ts +1 -1
- package/lib/mobx.es6.js +287 -27
- package/lib/mobx.js +330 -33
- package/lib/mobx.min.js +1 -1
- package/lib/mobx.min.js.map +1 -1
- package/lib/mobx.module.js +329 -34
- package/lib/mobx.umd.js +330 -33
- package/lib/mobx.umd.min.js +1 -1
- package/lib/mobx.umd.min.js.map +1 -1
- package/lib/types/observableset.d.ts +49 -0
- package/lib/types/observablevalue.d.ts +4 -2
- package/lib/utils/utils.d.ts +1 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
# 5.9.0 / 4.9.0
|
|
2
|
+
|
|
3
|
+
**Features**
|
|
4
|
+
|
|
5
|
+
* Introduced support for observable sets! Through [#1592](https://github.com/mobxjs/mobx/pull/1592) by [@newraina](https://github.com/newraina)
|
|
6
|
+
* `observable.box` now accepts an `equals` option, to be able to pass a custom comparision function. Through [#1862](https://github.com/mobxjs/mobx/pull/1862), [#1874](https://github.com/mobxjs/mobx/pull/1874) by [@fi3ework](https://github.com/fi3ework). Fixes [#1580](https://github.com/mobxjs/mobx/issues/1580)
|
|
7
|
+
* Improved logging of reactions; if an action throws an exception, errors in reactions that react to that are only logged as warnings. Fixes [#1836](https://github.com/mobxjs/mobx/issues/1836)
|
|
8
|
+
|
|
9
|
+
**Fixes**
|
|
10
|
+
|
|
11
|
+
* Improved typings for `flow`, see [#1827](https://github.com/mobxjs/mobx/pull/1827) by [@xaviergonz](https://github.com/xaviergonz)
|
|
12
|
+
* Don't allow subclassing map, fixes [#1858](https://github.com/mobxjs/mobx/issues/1858)
|
|
13
|
+
* Fixed `trace(true)` not being able to handle multi-line comments in traced function. Fixes [#1850](https://github.com/mobxjs/mobx/issues/1850)
|
|
14
|
+
* `@computed` now introduces non-configurable properties, to fail fast on incorrect inheritance or property deletion. Fixes [#1867](https://github.com/mobxjs/mobx/issues/1867)
|
|
15
|
+
* The options `enforceActions` and `isolateGlobalState` now work correctly when used together. Fixes [#1869](https://github.com/mobxjs/mobx/issues/1869)
|
|
16
|
+
|
|
1
17
|
# 5.8.0 / 4.8.0
|
|
2
18
|
|
|
19
|
+
* MobX now requires TypeScript 3 (this was already the case in 5.7.0, but in this version the difference is actually noticeable in the typings).
|
|
3
20
|
* Fixed array dehancer sometimes skipping. Fixes [#1839](https://github.com/mobxjs/mobx/issues/1839) through [#1841](https://github.com/mobxjs/mobx/pull/1841) by [k-g-a](https://github.com/k-g-a)
|
|
4
21
|
* Fixed issue where webpack 4 wouldn't use the ESM module [#1834](https://github.com/mobxjs/mobx/pull/1834) by [mrtnbroder](https://github.com/mrtnbroder)
|
|
5
22
|
* Improved type inference for `flow` in TypeScript 3. Fixes [#1816](https://github.com/mobxjs/mobx/issue/1816) through [#1825](https://github.com/mobxjs/mobx/pull/1825) by [ismailhabib](https://github.com/ismailhabib)
|
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -88,11 +88,11 @@ MobX adds observable capabilities to existing data structures like objects, arra
|
|
|
88
88
|
This can simply be done by annotating your class properties with the [@observable](http://mobxjs.github.io/mobx/refguide/observable-decorator.html) decorator (ES.Next).
|
|
89
89
|
|
|
90
90
|
```javascript
|
|
91
|
-
import { observable } from
|
|
91
|
+
import { observable } from 'mobx';
|
|
92
92
|
|
|
93
93
|
class Todo {
|
|
94
94
|
id = Math.random();
|
|
95
|
-
@observable title =
|
|
95
|
+
@observable title = '';
|
|
96
96
|
@observable finished = false;
|
|
97
97
|
}
|
|
98
98
|
```
|
|
@@ -106,11 +106,11 @@ Or you can skip them altoghether, as MobX can be used fine without decorator _sy
|
|
|
106
106
|
Many MobX users prefer the slightly more concise decorator syntax, but the following snippet achieves the same:
|
|
107
107
|
|
|
108
108
|
```javascript
|
|
109
|
-
import { decorate, observable } from
|
|
109
|
+
import { decorate, observable } from 'mobx';
|
|
110
110
|
|
|
111
111
|
class Todo {
|
|
112
112
|
id = Math.random();
|
|
113
|
-
title =
|
|
113
|
+
title = '';
|
|
114
114
|
finished = false;
|
|
115
115
|
}
|
|
116
116
|
decorate(Todo, {
|
|
@@ -173,7 +173,7 @@ class TodoListView extends Component {
|
|
|
173
173
|
const TodoView = observer(({todo}) =>
|
|
174
174
|
<li>
|
|
175
175
|
<input
|
|
176
|
-
type=
|
|
176
|
+
type='checkbox'
|
|
177
177
|
checked={todo.finished}
|
|
178
178
|
onClick={() => todo.finished = !todo.finished}
|
|
179
179
|
/>{todo.title}
|
|
@@ -197,7 +197,7 @@ For example the following `autorun` prints a log message each time the amount of
|
|
|
197
197
|
|
|
198
198
|
```javascript
|
|
199
199
|
autorun(() => {
|
|
200
|
-
console.log(
|
|
200
|
+
console.log(`Tasks left: ${ todos.unfinishedTodoCount }`)
|
|
201
201
|
})
|
|
202
202
|
```
|
|
203
203
|
|
|
@@ -227,8 +227,8 @@ There is no technical need for firing events, calling a dispatcher, etc. A React
|
|
|
227
227
|
|
|
228
228
|
```javascript
|
|
229
229
|
store.todos.push(
|
|
230
|
-
new Todo(
|
|
231
|
-
new Todo(
|
|
230
|
+
new Todo('Get Coffee'),
|
|
231
|
+
new Todo('Write simpler code')
|
|
232
232
|
);
|
|
233
233
|
store.todos[0].finished = true;
|
|
234
234
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IComputedValue, IObservable, IObservableArray, Lambda, ObservableMap } from "../internal";
|
|
2
|
-
export declare function onBecomeObserved(value: IObservable | IComputedValue<any> | IObservableArray<any> | ObservableMap<any, any>, listener: Lambda): Lambda;
|
|
1
|
+
import { IComputedValue, IObservable, IObservableArray, Lambda, ObservableMap, ObservableSet } from "../internal";
|
|
2
|
+
export declare function onBecomeObserved(value: IObservable | IComputedValue<any> | IObservableArray<any> | ObservableMap<any, any> | ObservableSet<any>, listener: Lambda): Lambda;
|
|
3
3
|
export declare function onBecomeObserved<K, V = any>(value: ObservableMap<K, V> | Object, property: K, listener: Lambda): Lambda;
|
|
4
|
-
export declare function onBecomeUnobserved(value: IObservable | IComputedValue<any> | IObservableArray<any> | ObservableMap<any, any>, listener: Lambda): Lambda;
|
|
4
|
+
export declare function onBecomeUnobserved(value: IObservable | IComputedValue<any> | IObservableArray<any> | ObservableMap<any, any> | ObservableSet<any>, listener: Lambda): Lambda;
|
|
5
5
|
export declare function onBecomeUnobserved<K, V = any>(value: ObservableMap<K, V> | Object, property: K, listener: Lambda): Lambda;
|
package/lib/api/flow.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export declare type CancellablePromise<T> = Promise<T> & {
|
|
2
2
|
cancel(): void;
|
|
3
3
|
};
|
|
4
|
-
export interface
|
|
5
|
-
|
|
6
|
-
return?(value?: any): IteratorResult<T> | Promise<IteratorResult<T>>;
|
|
7
|
-
throw?(e?: any): IteratorResult<T> | Promise<IteratorResult<T>>;
|
|
4
|
+
export interface FlowYield {
|
|
5
|
+
"!!flowYield": undefined;
|
|
8
6
|
}
|
|
9
|
-
export
|
|
7
|
+
export interface FlowReturn<T> {
|
|
8
|
+
"!!flowReturn": T;
|
|
9
|
+
}
|
|
10
|
+
export declare type FlowReturnType<R> = IfAllAreFlowYieldThenVoid<R extends FlowReturn<infer FR> ? FR extends Promise<infer FRP> ? FRP : FR : R extends Promise<any> ? FlowYield : R>;
|
|
11
|
+
export declare type IfAllAreFlowYieldThenVoid<R> = Exclude<R, FlowYield> extends never ? void : Exclude<R, FlowYield>;
|
|
12
|
+
export declare function flow<R, Args extends any[]>(generator: (...args: Args) => IterableIterator<R>): (...args: Args) => CancellablePromise<FlowReturnType<R>>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IObservableArray, IObservableValue, Lambda, ObservableMap } from "../internal";
|
|
1
|
+
import { IObservableArray, IObservableValue, Lambda, ObservableMap, ObservableSet } from "../internal";
|
|
2
2
|
export declare type ReadInterceptor<T> = (value: any) => T;
|
|
3
3
|
/** Experimental feature right now, tested indirectly via Mobx-State-Tree */
|
|
4
4
|
export declare function interceptReads<T>(value: IObservableValue<T>, handler: ReadInterceptor<T>): Lambda;
|
|
5
5
|
export declare function interceptReads<T>(observableArray: IObservableArray<T>, handler: ReadInterceptor<T>): Lambda;
|
|
6
6
|
export declare function interceptReads<K, V>(observableMap: ObservableMap<K, V>, handler: ReadInterceptor<V>): Lambda;
|
|
7
|
+
export declare function interceptReads<V>(observableSet: ObservableSet<V>, handler: ReadInterceptor<V>): Lambda;
|
|
7
8
|
export declare function interceptReads(object: Object, property: string, handler: ReadInterceptor<any>): Lambda;
|
package/lib/api/intercept.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IArrayWillChange, IArrayWillSplice, IInterceptor, IMapWillChange, IObjectWillChange, IObservableArray, IObservableValue, IValueWillChange, Lambda, ObservableMap } from "../internal";
|
|
1
|
+
import { IArrayWillChange, IArrayWillSplice, IInterceptor, IMapWillChange, IObjectWillChange, IObservableArray, IObservableValue, IValueWillChange, Lambda, ObservableMap, ObservableSet, ISetWillChange } from "../internal";
|
|
2
2
|
export declare function intercept<T>(value: IObservableValue<T>, handler: IInterceptor<IValueWillChange<T>>): Lambda;
|
|
3
3
|
export declare function intercept<T>(observableArray: IObservableArray<T>, handler: IInterceptor<IArrayWillChange<T> | IArrayWillSplice<T>>): Lambda;
|
|
4
4
|
export declare function intercept<K, V>(observableMap: ObservableMap<K, V>, handler: IInterceptor<IMapWillChange<K, V>>): Lambda;
|
|
5
|
+
export declare function intercept<V>(observableMap: ObservableSet<V>, handler: IInterceptor<ISetWillChange<V>>): Lambda;
|
|
5
6
|
export declare function intercept<K, V>(observableMap: ObservableMap<K, V>, property: K, handler: IInterceptor<IValueWillChange<V>>): Lambda;
|
|
6
7
|
export declare function intercept(object: Object, handler: IInterceptor<IObjectWillChange>): Lambda;
|
|
7
8
|
export declare function intercept<T extends Object, K extends keyof T>(object: T, property: K, handler: IInterceptor<IValueWillChange<any>>): Lambda;
|
package/lib/api/object-api.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { IObservableArray, ObservableMap } from "../internal";
|
|
1
|
+
import { IObservableArray, ObservableMap, ObservableSet } from "../internal";
|
|
2
2
|
export declare function keys<K>(map: ObservableMap<K, any>): ReadonlyArray<K>;
|
|
3
3
|
export declare function keys<T>(ar: IObservableArray<T>): ReadonlyArray<number>;
|
|
4
|
+
export declare function keys<T>(set: ObservableSet<T>): ReadonlyArray<T>;
|
|
4
5
|
export declare function keys<T extends Object>(obj: T): ReadonlyArray<string>;
|
|
5
6
|
export declare function values<K, T>(map: ObservableMap<K, T>): ReadonlyArray<T>;
|
|
7
|
+
export declare function values<T>(set: ObservableSet<T>): ReadonlyArray<T>;
|
|
6
8
|
export declare function values<T>(ar: IObservableArray<T>): ReadonlyArray<T>;
|
|
7
9
|
export declare function values<T = any>(obj: T): ReadonlyArray<any>;
|
|
8
10
|
export declare function entries<K, T>(map: ObservableMap<K, T>): ReadonlyArray<[K, T]>;
|
|
11
|
+
export declare function entries<T>(set: ObservableSet<T>): ReadonlyArray<[T, T]>;
|
|
9
12
|
export declare function entries<T>(ar: IObservableArray<T>): ReadonlyArray<[number, T]>;
|
|
10
13
|
export declare function entries<T = any>(obj: T): ReadonlyArray<[string, any]>;
|
|
11
14
|
export declare function set<V>(obj: ObservableMap<string, V>, values: {
|
|
@@ -18,9 +21,11 @@ export declare function set<T extends Object>(obj: T, values: {
|
|
|
18
21
|
}): any;
|
|
19
22
|
export declare function set<T extends Object>(obj: T, key: string, value: any): any;
|
|
20
23
|
export declare function remove<K, V>(obj: ObservableMap<K, V>, key: K): any;
|
|
24
|
+
export declare function remove<T>(obj: ObservableSet<T>, key: T): any;
|
|
21
25
|
export declare function remove<T>(obj: IObservableArray<T>, index: number): any;
|
|
22
26
|
export declare function remove<T extends Object>(obj: T, key: string): any;
|
|
23
27
|
export declare function has<K>(obj: ObservableMap<K, any>, key: K): boolean;
|
|
28
|
+
export declare function has<T>(obj: ObservableSet<T>, key: T): boolean;
|
|
24
29
|
export declare function has<T>(obj: IObservableArray<T>, index: number): boolean;
|
|
25
30
|
export declare function has<T extends Object>(obj: T, key: string): boolean;
|
|
26
31
|
export declare function get<K, V>(obj: ObservableMap<K, V>, key: K): V | undefined;
|
package/lib/api/observable.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { IEnhancer, IObservableArray, IObservableDecorator, IObservableMapInitialValues, IObservableObject, IObservableValue, ObservableMap } from "../internal";
|
|
1
|
+
import { IEnhancer, IEqualsComparer, IObservableArray, IObservableDecorator, IObservableMapInitialValues, IObservableSetInitialValues, IObservableObject, IObservableValue, ObservableMap, ObservableSet } from "../internal";
|
|
2
2
|
export declare type CreateObservableOptions = {
|
|
3
3
|
name?: string;
|
|
4
|
+
equals?: IEqualsComparer<any>;
|
|
4
5
|
deep?: boolean;
|
|
5
6
|
defaultDecorator?: IObservableDecorator;
|
|
6
7
|
proxy?: boolean;
|
|
@@ -21,6 +22,7 @@ export interface IObservableFactory {
|
|
|
21
22
|
export interface IObservableFactories {
|
|
22
23
|
box<T = any>(value?: T, options?: CreateObservableOptions): IObservableValue<T>;
|
|
23
24
|
array<T = any>(initialValues?: T[], options?: CreateObservableOptions): IObservableArray<T>;
|
|
25
|
+
set<T = any>(initialValues?: IObservableSetInitialValues<T>, options?: CreateObservableOptions): ObservableSet<T>;
|
|
24
26
|
map<K = any, V = any>(initialValues?: IObservableMapInitialValues<K, V>, options?: CreateObservableOptions): ObservableMap<K, V>;
|
|
25
27
|
object<T = any>(props: T, decorators?: {
|
|
26
28
|
[K in keyof T]?: Function;
|
package/lib/api/observe.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { IArrayChange, IArraySplice, IComputedValue, IMapDidChange, IObjectDidChange, IObservableArray, IObservableValue, IValueDidChange, Lambda, ObservableMap } from "../internal";
|
|
1
|
+
import { IArrayChange, IArraySplice, IComputedValue, IMapDidChange, IObjectDidChange, IObservableArray, IObservableValue, IValueDidChange, Lambda, ObservableMap, ObservableSet, ISetDidChange } from "../internal";
|
|
2
2
|
export declare function observe<T>(value: IObservableValue<T> | IComputedValue<T>, listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
|
|
3
3
|
export declare function observe<T>(observableArray: IObservableArray<T>, listener: (change: IArrayChange<T> | IArraySplice<T>) => void, fireImmediately?: boolean): Lambda;
|
|
4
|
+
export declare function observe<V>(observableMap: ObservableSet<V>, listener: (change: ISetDidChange<V>) => void, fireImmediately?: boolean): Lambda;
|
|
4
5
|
export declare function observe<K, V>(observableMap: ObservableMap<K, V>, listener: (change: IMapDidChange<K, V>) => void, fireImmediately?: boolean): Lambda;
|
|
5
6
|
export declare function observe<K, V>(observableMap: ObservableMap<K, V>, property: K, listener: (change: IValueDidChange<V>) => void, fireImmediately?: boolean): Lambda;
|
|
6
7
|
export declare function observe(object: Object, listener: (change: IObjectDidChange) => void, fireImmediately?: boolean): Lambda;
|
package/lib/internal.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export * from "./types/intercept-utils";
|
|
|
38
38
|
export * from "./types/listen-utils";
|
|
39
39
|
export * from "./types/observablearray";
|
|
40
40
|
export * from "./types/observablemap";
|
|
41
|
+
export * from "./types/observableset";
|
|
41
42
|
export * from "./types/observableobject";
|
|
42
43
|
export * from "./types/type-utils";
|
|
43
44
|
export * from "./utils/eq";
|
package/lib/mobx.d.ts
CHANGED
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* - utils/ Utility stuff.
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
|
-
export { IObservable, IDepTreeNode, Reaction, IReactionPublic, IReactionDisposer, IDerivation, untracked, IDerivationState, IAtom, createAtom, IAction, spy, IComputedValue, IEqualsComparer, comparer, IEnhancer, IInterceptable, IInterceptor, IListenable, IObjectWillChange, IObjectDidChange, IObservableObject, isObservableObject, IValueDidChange, IValueWillChange, IObservableValue, isObservableValue as isBoxedObservable, IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice, isObservableArray, IKeyValueMap, ObservableMap, IMapEntries, IMapEntry, IMapWillChange, IMapDidChange, isObservableMap, IObservableMapInitialValues, transaction, observable, IObservableFactory, IObservableFactories, computed, IComputed, isObservable, isObservableProp, isComputed, isComputedProp, extendObservable, observe, intercept, autorun, IAutorunOptions, reaction, IReactionOptions, when, IWhenOptions, action, isAction, runInAction, IActionFactory, keys, values, entries, set, remove, has, get, decorate, configure, onBecomeObserved, onBecomeUnobserved, flow, toJS, trace, IObserverTree, IDependencyTree, getDependencyTree, getObserverTree, resetGlobalState as _resetGlobalState, getGlobalState as _getGlobalState, getDebugName, getAtom, getAdministration as _getAdministration, allowStateChanges as _allowStateChanges, allowStateChangesInsideComputed as _allowStateChangesInsideComputed, Lambda, isArrayLike, $mobx, isComputingDerivation as _isComputingDerivation, onReactionError, interceptReads as _interceptReads, IComputedValueOptions } from "./internal";
|
|
18
|
+
export { IObservable, IDepTreeNode, Reaction, IReactionPublic, IReactionDisposer, IDerivation, untracked, IDerivationState, IAtom, createAtom, IAction, spy, IComputedValue, IEqualsComparer, comparer, IEnhancer, IInterceptable, IInterceptor, IListenable, IObjectWillChange, IObjectDidChange, IObservableObject, isObservableObject, IValueDidChange, IValueWillChange, IObservableValue, isObservableValue as isBoxedObservable, IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice, isObservableArray, IKeyValueMap, ObservableMap, IMapEntries, IMapEntry, IMapWillChange, IMapDidChange, isObservableMap, IObservableMapInitialValues, ObservableSet, isObservableSet, ISetDidChange, ISetWillChange, IObservableSetInitialValues, transaction, observable, IObservableFactory, IObservableFactories, computed, IComputed, isObservable, isObservableProp, isComputed, isComputedProp, extendObservable, observe, intercept, autorun, IAutorunOptions, reaction, IReactionOptions, when, IWhenOptions, action, isAction, runInAction, IActionFactory, keys, values, entries, set, remove, has, get, decorate, configure, onBecomeObserved, onBecomeUnobserved, flow, toJS, trace, IObserverTree, IDependencyTree, getDependencyTree, getObserverTree, resetGlobalState as _resetGlobalState, getGlobalState as _getGlobalState, getDebugName, getAtom, getAdministration as _getAdministration, allowStateChanges as _allowStateChanges, allowStateChangesInsideComputed as _allowStateChangesInsideComputed, Lambda, isArrayLike, $mobx, isComputingDerivation as _isComputingDerivation, onReactionError, interceptReads as _interceptReads, IComputedValueOptions } from "./internal";
|