Skip to content

Commit

Permalink
Simplified by removing computed ids
Browse files Browse the repository at this point in the history
  • Loading branch information
masylum committed Jul 12, 2016
1 parent 05d943b commit 076b691
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-rest",
"version": "0.0.6",
"version": "0.0.7",
"description": "REST conventions for mobx.",
"repository": {
"type": "git",
Expand Down
26 changes: 13 additions & 13 deletions src/Collection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals Class */
// @flow
import { observable, computed, action } from 'mobx'
import { observable, action } from 'mobx'
import Model from './Model'
import Api from './Api'
import arrayDiff from 'lodash.difference'
Expand Down Expand Up @@ -34,6 +34,17 @@ class Collection {
return Model
}

/**
* Gets the ids of all the items in the collection
*/
_ids (): Array<number> {
const ids = this.models.map((item) => item.id)
.filter(Boolean)

// LOL flow: https://github.com/facebook/flow/issues/1414
return ((ids.filter(Boolean): Array<any>): Array<number>)
}

/**
* Get a resource at a given position
*/
Expand Down Expand Up @@ -84,7 +95,7 @@ class Collection {
): void {
if (remove) {
const ids = models.map((d) => d.id)
this.remove(arrayDiff(this.ids, ids))
this.remove(arrayDiff(this._ids(), ids))
}

models.forEach((attributes) => {
Expand Down Expand Up @@ -152,17 +163,6 @@ class Collection {
this.error = {label, body}
})
}

/**
* Gets the ids of all the items in the collection
*/
@computed get ids (): Array<number> {
const ids = this.models.map((item) => item.id)
.filter(Boolean)

// LOL flow: https://github.com/facebook/flow/issues/1414
return ((ids.filter(Boolean): Array<any>): Array<number>)
}
}

export default Collection

0 comments on commit 076b691

Please sign in to comment.