mobx 6.0.0 → 6.0.4

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.
@@ -30,7 +30,7 @@ export declare function isGenerator(obj: any): boolean;
30
30
  export declare function addHiddenProp(object: any, propName: PropertyKey, value: any): void;
31
31
  export declare function addHiddenFinalProp(object: any, propName: PropertyKey, value: any): void;
32
32
  export declare function assertPropertyConfigurable(object: any, prop: PropertyKey): void;
33
- export declare function createInstanceofPredicate<T>(name: string, clazz: new (...args: any[]) => T): (x: any) => x is T;
33
+ export declare function createInstanceofPredicate<T>(name: string, theClass: new (...args: any[]) => T): (x: any) => x is T;
34
34
  export declare function isES6Map(thing: any): boolean;
35
35
  export declare function isES6Set(thing: any): thing is Set<any>;
36
36
  /**
package/package.json CHANGED
@@ -1,143 +1,77 @@
1
1
  {
2
- "name": "mobx",
3
- "version": "6.0.0",
4
- "description": "Simple, scalable state management.",
5
- "main": "dist/index.js",
6
- "module": "dist/mobx.esm.js",
7
- "umd:main": "dist/mobx.umd.production.min.js",
8
- "unpkg": "dist/mobx.umd.production.min.js",
9
- "jsnext:main": "dist/mobx.esm.js",
10
- "react-native": "dist/mobx.esm.js",
11
- "source": "src/mobx.ts",
12
- "typings": "dist/mobx.d.ts",
13
- "sideEffects": false,
14
- "scripts": {
15
- "test": "jest",
16
- "lint": "eslint src/**/*.ts",
17
- "watch": "jest --watch",
18
- "perf": "yarn build && yarn test:performance proxy && yarn test:performance legacy",
19
- "test:mixed-versions": "jest --testRegex mixed-versions",
20
- "test:check": "yarn test:types && yarn lint",
21
- "test:types": "tsc --noEmit && yarn test:flow",
22
- "test:flow": "yarn build && flow check",
23
- "test:coverage": "yarn test -i --coverage",
24
- "test:performance": "PERSIST=true time node --expose-gc test/perf/index.js",
25
- "test:size": "yarn build && yarn import-size --report . observable computed autorun action",
26
- "test:codemod": "cd packages/mobx-undecorate && yarn test",
27
- "prettier": "prettier --write **/*.{js,ts,md}",
28
- "prebuild": "rimraf lib",
29
- "build": "tsdx build --name mobx --format esm,cjs,umd",
30
- "postbuild": "cp flow-typed/mobx.js dist/index.js.flow",
31
- "release": "node scripts/publish.js",
32
- "publish-script": "yarn release",
33
- "docs:build": "yarn --cwd website build",
34
- "docs:start": "yarn --cwd website start",
35
- "docs:publish": "yarn --cwd website publish-gh-pages",
36
- "prepare": "yarn dedup && yarn --cwd website install",
37
- "dedup": "npx yarn-deduplicate --strategy fewer yarn.lock"
38
- },
39
- "repository": {
40
- "type": "git",
41
- "url": "https://github.com/mobxjs/mobx.git"
42
- },
43
- "author": "Michel Weststrate",
44
- "license": "MIT",
45
- "funding": {
46
- "type": "opencollective",
47
- "url": "https://opencollective.com/mobx"
48
- },
49
- "bugs": {
50
- "url": "https://github.com/mobxjs/mobx/issues"
51
- },
52
- "files": [
53
- "src",
54
- "dist",
55
- "LICENSE",
56
- "README.md"
57
- ],
58
- "homepage": "https://mobx.js.org/",
59
- "dependencies": {},
60
- "devDependencies": {
61
- "@babel/core": "^7.9.0",
62
- "@babel/plugin-proposal-class-properties": "^7.8.3",
63
- "@babel/plugin-proposal-decorators": "^7.8.3",
64
- "@babel/plugin-transform-runtime": "^7.9.0",
65
- "@babel/preset-env": "^7.9.5",
66
- "@babel/preset-typescript": "^7.9.0",
67
- "@babel/runtime": "^7.9.2",
68
- "@types/jest": "^25.2.1",
69
- "@types/node": "^11.15.12",
70
- "@typescript-eslint/eslint-plugin": "^2.29.0",
71
- "@typescript-eslint/parser": "^4.1.1",
72
- "babel-jest": "^25.4.0",
73
- "conditional-type-checks": "^1.0.5",
74
- "coveralls": "^3.1.0",
75
- "eslint": "^6.8.0",
76
- "flow-bin": "^0.123.0",
77
- "husky": "^4.2.5",
78
- "import-size": "^1.0.2",
79
- "iterall": "^1.3.0",
80
- "jest": "^25.4.0",
81
- "jscodeshift": "^0.7.0",
82
- "lint-staged": "^10.1.7",
83
- "prettier": "^2.0.5",
84
- "pretty-quick": "2.0.1",
85
- "prompts": "^2.3.2",
86
- "semver": "^7.3.2",
87
- "serializr": "^2.0.3",
88
- "shelljs": "^0.8.4",
89
- "tape": "^5.0.0",
90
- "ts-jest": "^25.4.0",
91
- "tsdx": "^0.13.2",
92
- "typescript": "^4.0.2"
93
- },
94
- "keywords": [
95
- "mobx",
96
- "mobservable",
97
- "observable",
98
- "react-component",
99
- "react",
100
- "reactjs",
101
- "reactive",
102
- "model",
103
- "frp",
104
- "functional-reactive-programming",
105
- "state management",
106
- "data flow"
107
- ],
108
- "jest": {
109
- "globals": {
110
- "__DEV__": true,
111
- "ts-jest": {
112
- "tsConfig": "tsconfig.test.json"
113
- }
114
- },
115
- "setupFilesAfterEnv": [
116
- "<rootDir>/test/setup.js"
2
+ "name": "mobx",
3
+ "version": "6.0.4",
4
+ "description": "Simple, scalable state management.",
5
+ "source": "src/mobx.ts",
6
+ "main": "dist/index.js",
7
+ "umd:main": "dist/mobx.umd.production.min.js",
8
+ "unpkg": "dist/mobx.umd.production.min.js",
9
+ "jsdelivr": "dist/mobx.umd.production.min.js",
10
+ "jsnext:main": "dist/mobx.esm.production.min.js",
11
+ "module": "dist/mobx.esm.js",
12
+ "react-native": "dist/mobx.esm.js",
13
+ "types": "dist/mobx.d.ts",
14
+ "typings": "dist/mobx.d.ts",
15
+ "files": [
16
+ "src",
17
+ "dist",
18
+ "LICENSE",
19
+ "CHANGELOG.md",
20
+ "README.md"
117
21
  ],
118
- "transform": {
119
- "^.+\\.tsx?$": "ts-jest",
120
- "^.+\\.jsx?$": "babel-jest"
22
+ "sideEffects": false,
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/mobxjs/mobx.git"
121
26
  },
122
- "testRegex": "test/v[4|5]/base/.*\\.(t|j)sx?$",
123
- "moduleFileExtensions": [
124
- "ts",
125
- "tsx",
126
- "js",
127
- "jsx",
128
- "json"
129
- ],
130
- "testPathIgnorePatterns": [
131
- "/node_modules/",
132
- "/\\./"
27
+ "author": "Michel Weststrate",
28
+ "license": "MIT",
29
+ "funding": {
30
+ "type": "opencollective",
31
+ "url": "https://opencollective.com/mobx"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/mobxjs/mobx/issues"
35
+ },
36
+ "homepage": "https://mobx.js.org/",
37
+ "dependencies": {},
38
+ "devDependencies": {
39
+ "@babel/core": "^7.9.0",
40
+ "@babel/plugin-proposal-class-properties": "^7.8.3",
41
+ "@babel/plugin-proposal-decorators": "^7.8.3",
42
+ "@babel/plugin-transform-runtime": "^7.9.0",
43
+ "@babel/preset-env": "^7.9.5",
44
+ "@babel/preset-typescript": "^7.9.0",
45
+ "@babel/runtime": "^7.9.2",
46
+ "conditional-type-checks": "^1.0.5",
47
+ "flow-bin": "^0.123.0"
48
+ },
49
+ "keywords": [
50
+ "mobx",
51
+ "mobservable",
52
+ "observable",
53
+ "react-component",
54
+ "react",
55
+ "reactjs",
56
+ "reactive",
57
+ "model",
58
+ "frp",
59
+ "functional-reactive-programming",
60
+ "state management",
61
+ "data flow"
133
62
  ],
134
- "watchPathIgnorePatterns": [
135
- "<rootDir>/node_modules/"
136
- ]
137
- },
138
- "husky": {
139
- "hooks": {
140
- "pre-commit": "pretty-quick --staged"
63
+ "scripts": {
64
+ "test": "jest",
65
+ "lint": "eslint src/**/*",
66
+ "build": "node ../../scripts/build.js mobx",
67
+ "build:test": "yarn build --target test",
68
+ "perf": "scripts/perf.sh",
69
+ "test:performance": "yarn perf proxy && yarn perf legacy",
70
+ "test:mixed-versions": "yarn test --testRegex mixed-versions",
71
+ "test:types": "tsc --noEmit",
72
+ "test:flow": "flow check",
73
+ "test:coverage": "yarn test -i --coverage",
74
+ "test:size": "yarn import-size --report . observable computed autorun action",
75
+ "prepublish": "node ./scripts/prepublish.js && yarn build --target publish"
141
76
  }
142
- }
143
- }
77
+ }
@@ -22,6 +22,6 @@ export type AnnotationMapEntry =
22
22
  // AdditionalFields can be used to declare additional keys that can be used, for example to be able to
23
23
  // declare annotations for private/ protected members, see #2339
24
24
  export type AnnotationsMap<T, AdditionalFields extends PropertyKey> = {
25
- [P in keyof T]?: AnnotationMapEntry
25
+ [P in Exclude<keyof T, "toString">]?: AnnotationMapEntry
26
26
  } &
27
27
  Record<AdditionalFields, AnnotationMapEntry>
@@ -91,7 +91,7 @@ export function makeProperty(
91
91
  ): void {
92
92
  const { target_: target } = adm
93
93
  const defaultAnnotation: Annotation | undefined = observable // ideally grap this from adm's defaultEnahncer instead!
94
- const origAnnotation = annotation
94
+ const originAnnotation = annotation
95
95
  if (annotation === true) {
96
96
  annotation = getInferredAnnotation(descriptor, defaultAnnotation, autoBind)
97
97
  }
@@ -162,9 +162,9 @@ export function makeProperty(
162
162
  die(
163
163
  `Cannot decorate '${key.toString()}': observable cannot be used on setter / getter properties.`
164
164
  )
165
- // if the origAnnotation was true, preferred the adm's default enhancer over the inferred one
165
+ // if the originAnnotation was true, preferred the adm's default enhancer over the inferred one
166
166
  const enhancer =
167
- origAnnotation === true
167
+ originAnnotation === true
168
168
  ? adm.defaultEnhancer_
169
169
  : getEnhancerFromAnnotation(annotation)
170
170
  adm.addObservableProp_(key, descriptor.value, enhancer)
@@ -182,7 +182,7 @@ export function makeProperty(
182
182
 
183
183
  // Hack based on https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-322267089
184
184
  // We need this, because otherwise, AdditionalKeys is going to be inferred to be any
185
- // set of superfluos keys. But, we rather want to get a compile error unless AdditionalKeys is
185
+ // set of superfluous keys. But, we rather want to get a compile error unless AdditionalKeys is
186
186
  // _explicity_ passed as generic argument
187
187
  // Fixes: https://github.com/mobxjs/mobx/issues/2325#issuecomment-691070022
188
188
  type NoInfer<T> = [T][T extends any ? 0 : never]
@@ -222,7 +222,7 @@ export function makeObservable<T, AdditionalKeys extends PropertyKey = never>(
222
222
 
223
223
  export function makeAutoObservable<T extends Object, AdditionalKeys extends PropertyKey = never>(
224
224
  target: T,
225
- excludes?: AnnotationsMap<T, NoInfer<AdditionalKeys>>,
225
+ overrides?: AnnotationsMap<T, NoInfer<AdditionalKeys>>,
226
226
  options?: CreateObservableOptions
227
227
  ): T {
228
228
  const proto = Object.getPrototypeOf(target)
@@ -238,7 +238,7 @@ export function makeAutoObservable<T extends Object, AdditionalKeys extends Prop
238
238
  // shortcut, reuse inferred annotations for this type from the previous time
239
239
  annotations = proto[CACHED_ANNOTATIONS] as any
240
240
  } else {
241
- annotations = { ...excludes }
241
+ annotations = { ...overrides }
242
242
  extractAnnotationsFromObject(target, annotations, options)
243
243
  if (!isPlain) {
244
244
  extractAnnotationsFromProto(proto, annotations, options)
@@ -255,9 +255,12 @@ function extractAnnotationsFromObject(
255
255
  options: CreateObservableOptions | undefined
256
256
  ) {
257
257
  const autoBind = !!options?.autoBind
258
- const defaultAnnotation: Annotation = options?.deep
259
- ? observable.deep
260
- : options?.defaultDecorator ?? observable.deep
258
+ const defaultAnnotation: Annotation =
259
+ options?.deep === undefined
260
+ ? options?.defaultDecorator ?? observable.deep
261
+ : options?.deep
262
+ ? observable.deep
263
+ : observable.ref
261
264
  Object.entries(getOwnPropertyDescriptors(target)).forEach(([key, descriptor]) => {
262
265
  if (key in collector || key === "constructor") return
263
266
  collector[key] = getInferredAnnotation(descriptor, defaultAnnotation, autoBind)
@@ -85,7 +85,7 @@ export interface IActionRunInfo {
85
85
 
86
86
  export function _startAction(
87
87
  actionName: string,
88
- canRunAsDeriviation: boolean, // true for autoAction
88
+ canRunAsDerivation: boolean, // true for autoAction
89
89
  scope: any,
90
90
  args?: IArguments
91
91
  ): IActionRunInfo {
@@ -93,16 +93,16 @@ export function _startAction(
93
93
  let startTime_: number = 0
94
94
  if (__DEV__ && notifySpy_) {
95
95
  startTime_ = Date.now()
96
- const flattendArgs = args ? Array.from(args) : EMPTY_ARRAY
96
+ const flattenedArgs = args ? Array.from(args) : EMPTY_ARRAY
97
97
  spyReportStart({
98
98
  type: ACTION,
99
99
  name: actionName,
100
100
  object: scope,
101
- arguments: flattendArgs
101
+ arguments: flattenedArgs
102
102
  })
103
103
  }
104
104
  const prevDerivation_ = globalState.trackingDerivation
105
- const runAsAction = !canRunAsDeriviation || !prevDerivation_
105
+ const runAsAction = !canRunAsDerivation || !prevDerivation_
106
106
  startBatch()
107
107
  let prevAllowStateChanges_ = globalState.allowStateChanges // by default preserve previous allow
108
108
  if (runAsAction) {
@@ -109,7 +109,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
109
109
  *
110
110
  * The `equals` property specifies the comparer function to use to determine if a newly produced
111
111
  * value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
112
- * compares based on identity comparison (===), and `structualComparer` deeply compares the structure.
112
+ * compares based on identity comparison (===), and `structuralComparer` deeply compares the structure.
113
113
  * Structural comparison can be convenient if you always produce a new aggregated object and
114
114
  * don't want to notify observers if it is structurally the same.
115
115
  * This is useful for working with vectors, mouse coordinates etc.
@@ -324,9 +324,14 @@ export function asObservableObject(
324
324
 
325
325
  if (__DEV__ && !Object.isExtensible(target))
326
326
  die("Cannot make the designated object observable; it is not extensible")
327
- if (!isPlainObject(target))
328
- name = (target.constructor.name || "ObservableObject") + "@" + getNextId()
329
- if (!name) name = "ObservableObject@" + getNextId()
327
+
328
+ if (!name) {
329
+ if (isPlainObject(target)) {
330
+ name = "ObservableObject@" + getNextId()
331
+ } else {
332
+ name = (target.constructor.name || "ObservableObject") + "@" + getNextId()
333
+ }
334
+ }
330
335
 
331
336
  const adm = new ObservableObjectAdministration(
332
337
  target,
@@ -59,7 +59,8 @@ export interface IObservableValue<T> {
59
59
 
60
60
  const CREATE = "create"
61
61
 
62
- export class ObservableValue<T> extends Atom
62
+ export class ObservableValue<T>
63
+ extends Atom
63
64
  implements IObservableValue<T>, IInterceptable<IValueWillChange<T>>, IListenable {
64
65
  hasUnreportedChange_ = false
65
66
  interceptors_
@@ -1,4 +1,17 @@
1
- export function getGlobal(): any {
2
- // @ts-ignore
3
- return typeof global !== "undefined" ? global : window
1
+ declare const window: any
2
+ declare const self: any
3
+
4
+ const mockGlobal = {}
5
+
6
+ export function getGlobal() {
7
+ if (typeof window !== "undefined") {
8
+ return window
9
+ }
10
+ if (typeof global !== "undefined") {
11
+ return global
12
+ }
13
+ if (typeof self !== "undefined") {
14
+ return self
15
+ }
16
+ return mockGlobal
4
17
  }
@@ -128,10 +128,10 @@ export function assertPropertyConfigurable(object: any, prop: PropertyKey) {
128
128
 
129
129
  export function createInstanceofPredicate<T>(
130
130
  name: string,
131
- clazz: new (...args: any[]) => T
131
+ theClass: new (...args: any[]) => T
132
132
  ): (x: any) => x is T {
133
133
  const propName = "isMobX" + name
134
- clazz.prototype[propName] = true
134
+ theClass.prototype[propName] = true
135
135
  return function (x) {
136
136
  return isObject(x) && x[propName] === true
137
137
  } as any