From 4e2b137d5b5c731ed5c5b6663bd0b70aa430f554 Mon Sep 17 00:00:00 2001 From: Pau Ramon Revilla Date: Thu, 9 Mar 2017 18:50:00 +0100 Subject: [PATCH] Migrated to mobx 3 --- package.json | 24 ++++++++++++------------ src/Collection.js | 16 ++++++++-------- src/Model.js | 19 ++++++++----------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 8257fe9..a2f17d5 100644 --- a/package.json +++ b/package.json @@ -16,23 +16,23 @@ }, "dependencies": { "lodash": "^4.17.4", - "mobx": "^2.7.0" + "mobx": "^3.1.5" }, "devDependencies": { - "babel-cli": "^6.10.1", - "babel-core": "^6.10.4", + "babel-cli": "^6.23.0", + "babel-core": "^6.23.1", "babel-eslint": "^7.1.1", - "babel-jest": "^18.0.0", + "babel-jest": "^19.0.0", "babel-plugin-transform-decorators-legacy": "^1.3.4", - "babel-plugin-transform-flow-strip-types": "^6.8.0", - "babel-polyfill": "^6.9.1", - "babel-preset-es2015": "^6.3.13", - "babel-preset-stage-1": "^6.5.0", - "babel-register": "^6.9.0", - "flow-bin": "^0.38.0", - "jest": "^18.1.0", + "babel-plugin-transform-flow-strip-types": "^6.22.0", + "babel-polyfill": "^6.23.0", + "babel-preset-es2015": "^6.22.0", + "babel-preset-stage-1": "^6.22.0", + "babel-register": "^6.23.0", + "flow-bin": "^0.41.0", + "jest": "^19.0.2", "snazzy": "^6.0.0", - "standard": "^8.6.0" + "standard": "^9.0.1" }, "main": "lib", "scripts": { diff --git a/src/Collection.js b/src/Collection.js index bfcd24b..f11275e 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -1,5 +1,5 @@ // @flow -import { observable, action, asReference, IObservableArray, runInAction } from 'mobx' +import { observable, action, IObservableArray, runInAction } from 'mobx' import Model from './Model' import { isEmpty, @@ -15,9 +15,9 @@ import apiClient from './apiClient' import type { Label, CreateOptions, ErrorType, Request, SetOptions, Id } from './types' export default class Collection { - @observable request: ?Request = null - @observable error: ?ErrorType = null - @observable models: IObservableArray = [] + request: ?Request = observable.shallowObject(null) + error: ?ErrorType = observable.shallowObject(null) + models: IObservableArray = observable.shallowArray([]) constructor (data: Array<{[key: string]: any}> = []) { this.set(data) @@ -194,14 +194,14 @@ export default class Collection { : last(this.add([attributesOrModel])) model.request = { label, - abort: asReference(abort), + abort, progress: 0 } } this.request = { label, - abort: asReference(abort), + abort, progress: 0 } @@ -251,7 +251,7 @@ export default class Collection { this.request = { label, - abort: asReference(abort), + abort, progress: 0 } @@ -294,7 +294,7 @@ export default class Collection { this.request = { label, - abort: asReference(abort), + abort, progress: 0 } diff --git a/src/Model.js b/src/Model.js index bff3e7e..2e4153f 100644 --- a/src/Model.js +++ b/src/Model.js @@ -1,10 +1,7 @@ // @flow import { observable, - asMap, - asFlat, action, - asReference, ObservableMap, computed, runInAction @@ -24,15 +21,15 @@ import type { } from './types' export default class Model { - @observable request: ?Request = null - @observable error: ?ErrorType = asFlat(null) + request: ?Request = observable.shallowObject(null) + error: ?ErrorType = observable.shallowObject(null) optimisticId: OptimisticId = uniqueId('i_') collection: ?Collection<*> = null attributes: ObservableMap constructor (attributes: {[key: string]: any} = {}) { - this.attributes = asMap(attributes) + this.attributes = observable.map(attributes) } /** @@ -138,7 +135,7 @@ export default class Model { this.request = { label, - abort: asReference(abort), + abort, progress: 0 } @@ -210,7 +207,7 @@ export default class Model { this.request = { label, - abort: asReference(abort), + abort, progress: 0 } @@ -261,7 +258,7 @@ export default class Model { if (optimistic) { this.request = { label, - abort: asReference(abort), + abort, progress: 0 } } @@ -310,7 +307,7 @@ export default class Model { this.request = { label, - abort: asReference(abort), + abort, progress: 0 } @@ -356,7 +353,7 @@ export default class Model { this.request = { label, - abort: asReference(abort), + abort, progress: 0 }