Skip to content

Commit

Permalink
Merge branch 'master' into allow-state-changes-inside-computed
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergonz committed Sep 20, 2018
2 parents e15bc78 + ed4827f commit 4808b29
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 166 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# 5.1.0
# 5.1.2 / 4.4.2

* Fixed [#1650](https://github.com/mobxjs/mobx/issues/1650), decorating fields with the name `toString` does not behave correctly.

# 5.1.1 / 4.4.1

* Improved typings of `decorate`, see [#1711](https://github.com/mobxjs/mobx/pull/1711) by [makepost](https://github.com/makepost)

# 5.1.0 / 4.4.0

* Improved handling of multiple MobX instances. MobX will no longer complain about being loaded multiple times (one should still prevent it though, to prevent blowing up bundle size!), but merge internal state by default. If multiple MobX versions need to be loaded, call `configure({ isolateGlobalState: true })`. Note that this means that observables from the different MobX instances won't cooperate. Fixes [#1681](https://github.com/mobxjs/mobx/issues/1681), [#1082](https://github.com/mobxjs/mobx/issues/1082)
* `enforceActions` options now supports the values: `"never"`, `"observed"` and `"always"` to make the behavior more clear. Fixes [#1680](https://github.com/mobxjs/mobx/issues/1680), [#1473](https://github.com/mobxjs/mobx/issues/1473)
Expand Down Expand Up @@ -676,6 +684,12 @@ Since this behavior is probably not used outside Mendix, it has been deprecated

See [#621](https://github.com/mobxjs/mobx/issues/621)

### Using the @action decorator inside individual objects

Don't use the `@action` decorator on an individual object that you pass to `observable()` or `extendObservable()`. If you have code that looks like `observable({ @action f: () => {})`, you should change it to `observable({ f: action(() => {})`.

Whether or not this was ever a good idea is debatable, but it stopped working in this version. If you're using classes, it's a non-issue.

### Other changes

* **Breaking change:** The arguments to `observe` listeners for computed and boxed observables have changed and are now consistent with the other apis. Instead of invoking the callback with `(newValue: T, oldValue: T)` they are now invoked with a single change object: `(change: {newValue: T, oldValue: T, object, type: "update"})`
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx",
"version": "5.1.0",
"version": "5.1.2",
"description": "Simple, scalable state management.",
"main": "lib/mobx.js",
"umd:main": "lib/mobx.umd.js",
Expand Down Expand Up @@ -44,7 +44,7 @@
"@types/jest": "^21.1.9",
"@types/node": "^7.0.22",
"babel-core": "7.0.0-beta.3",
"babel-jest": "^22.0.4",
"babel-jest": "^23.6.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-preset-es2015": "7.0.0-beta.3",
"babel-preset-react": "7.0.0-beta.3",
Expand All @@ -57,7 +57,7 @@
"fs-extra": "^3.0.1",
"husky": "^0.14.3",
"iterall": "^1.0.2",
"jest": "^22.0.4",
"jest": "^23.6.0",
"lint-staged": "^3.6.1",
"lodash.intersection": "^3.2.0",
"ncp": "^2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/api/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export interface IActionFactory {
<T extends Function>(name: string, fn: T): T & IAction

// named decorator
(customName: string): (target: Object, key: string, baseDescriptor?: PropertyDescriptor) => void
(customName: string): (target: Object, key: string | symbol, baseDescriptor?: PropertyDescriptor) => void

// unnamed decorator
(target: Object, propertyKey: string, descriptor?: PropertyDescriptor): void
(target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): void

// @action.bound decorator
bound(target: Object, propertyKey: string, descriptor?: PropertyDescriptor): void
bound(target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): void
}

export var action: IActionFactory = function action(arg1, arg2?, arg3?, arg4?): any {
Expand Down
2 changes: 1 addition & 1 deletion src/api/observabledecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "../internal"

export type IObservableDecorator = {
(target: Object, property: string, descriptor?: PropertyDescriptor): void
(target: Object, property: string | symbol, descriptor?: PropertyDescriptor): void
enhancer: IEnhancer<any>
}

Expand Down
3 changes: 2 additions & 1 deletion src/mobx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ try {
process.env.NODE_ENV !== "production"
) {
console.warn(
"[mobx] you are running a minified build, but 'process.env.NODE_ENV' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle"
// Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
`[mobx] you are running a minified build, but 'process.env.NODE_ENV' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle`
)
}
})()
Expand Down
4 changes: 2 additions & 2 deletions src/types/observableobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ export function asObservableObject(
return adm
}

const observablePropertyConfigs = {}
const computedPropertyConfigs = {}
const observablePropertyConfigs = Object.create(null);
const computedPropertyConfigs = Object.create(null);

export function generateObservablePropConfig(propName) {
return (
Expand Down
3 changes: 2 additions & 1 deletion test/base/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test("decorate should work", function() {
}

decorate(Box, {
uninitialized: observable,
uninitialized: observable.ref,
undeclared: observable,
height: observable,
sizes: observable,
Expand Down Expand Up @@ -97,6 +97,7 @@ test("decorate should work", function() {

test("decorate should work with plain object", function() {
const box = {
/** @type {boolean | undefined} */
uninitialized: undefined,
height: 20,
sizes: [2],
Expand Down
22 changes: 11 additions & 11 deletions test/base/makereactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,7 @@ test("structural collections", () => {
}).toThrow("observable.struct should not be used with observable values")
})

test.skip("jest is behaving correctly", () => {
// this failing test is fixed here:
// https://github.com/facebook/jest/pull/6391
test("jest is behaving correctly", () => {
const symbol = Symbol("test")
const a = []
const b = []
Expand All @@ -702,8 +700,7 @@ test.skip("jest is behaving correctly", () => {
expect(a).not.toEqual(c)
})

test.skip("All non-enumerables should be treated equally!", () => {
// Bug filed here: https://github.com/facebook/jest/issues/6392
test("All non-enumerables should be treated equally!", () => {
const actual1 = {
x: 3
}
Expand All @@ -725,8 +722,7 @@ test.skip("All non-enumerables should be treated equally!", () => {
expect(actual2).toEqual({ x: 3 })
})

test.skip("jest object equals issue - reference", () => {
// Skip until https://github.com/facebook/jest/issues/6392 is resolved
test("jest object equals issue - reference", () => {
class Store {
constructor() {
mobx.extendObservable(this, { x: 3 })
Expand All @@ -738,8 +734,7 @@ test.skip("jest object equals issue - reference", () => {
expect(store).toEqual(new Store())
})

test.skip("jest object equals issue", () => {
// Skip until https://github.com/facebook/jest/issues/6392 is resolved
test("jest object equals issue", () => {
class Store {
@mobx.observable x = 2

Expand All @@ -752,12 +747,17 @@ test.skip("jest object equals issue", () => {
expect(store).toEqual(new Store())
})

test.skip("jest array equals issue", () => {
// Skip until https://github.com/facebook/jest/issues/6392 is resolved
test("jest array equals issue", () => {
class Store {
@mobx.observable things = []
}

const store = new Store()
expect(store.things).toEqual([])
})

test("#1650, toString is not treated correctly", () => {
const o = { a: "a", toString: "toString" }
const oo = mobx.observable(o)
expect(oo.toString).toBe("toString")
})

0 comments on commit 4808b29

Please sign in to comment.