Skip to content

Commit

Permalink
Migrated to mobx 3
Browse files Browse the repository at this point in the history
  • Loading branch information
masylum committed Mar 9, 2017
1 parent 4deec89 commit 4e2b137
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 8 additions & 8 deletions src/Collection.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,9 +15,9 @@ import apiClient from './apiClient'
import type { Label, CreateOptions, ErrorType, Request, SetOptions, Id } from './types'

export default class Collection<T: Model> {
@observable request: ?Request = null
@observable error: ?ErrorType = null
@observable models: IObservableArray<T> = []
request: ?Request = observable.shallowObject(null)
error: ?ErrorType = observable.shallowObject(null)
models: IObservableArray<T> = observable.shallowArray([])

constructor (data: Array<{[key: string]: any}> = []) {
this.set(data)
Expand Down Expand Up @@ -194,14 +194,14 @@ export default class Collection<T: Model> {
: last(this.add([attributesOrModel]))
model.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}
}

this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}

Expand Down Expand Up @@ -251,7 +251,7 @@ export default class Collection<T: Model> {

this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}

Expand Down Expand Up @@ -294,7 +294,7 @@ export default class Collection<T: Model> {

this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}

Expand Down
19 changes: 8 additions & 11 deletions src/Model.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @flow
import {
observable,
asMap,
asFlat,
action,
asReference,
ObservableMap,
computed,
runInAction
Expand All @@ -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)
}

/**
Expand Down Expand Up @@ -138,7 +135,7 @@ export default class Model {

this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}

Expand Down Expand Up @@ -210,7 +207,7 @@ export default class Model {

this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}

Expand Down Expand Up @@ -261,7 +258,7 @@ export default class Model {
if (optimistic) {
this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}
}
Expand Down Expand Up @@ -310,7 +307,7 @@ export default class Model {

this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}

Expand Down Expand Up @@ -356,7 +353,7 @@ export default class Model {

this.request = {
label,
abort: asReference(abort),
abort,
progress: 0
}

Expand Down

0 comments on commit 4e2b137

Please sign in to comment.