From 076b69134866a748b80677cf856279eb53dc0f67 Mon Sep 17 00:00:00 2001 From: Pau Ramon Revilla Date: Wed, 13 Jul 2016 01:01:50 +0200 Subject: [PATCH] Simplified by removing computed ids --- package.json | 2 +- src/Collection.js | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index e096bda..e8cf94d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mobx-rest", - "version": "0.0.6", + "version": "0.0.7", "description": "REST conventions for mobx.", "repository": { "type": "git", diff --git a/src/Collection.js b/src/Collection.js index f2ab9fc..7bc76e8 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -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' @@ -34,6 +34,17 @@ class Collection { return Model } + /** + * Gets the ids of all the items in the collection + */ + _ids (): Array { + const ids = this.models.map((item) => item.id) + .filter(Boolean) + + // LOL flow: https://github.com/facebook/flow/issues/1414 + return ((ids.filter(Boolean): Array): Array) + } + /** * Get a resource at a given position */ @@ -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) => { @@ -152,17 +163,6 @@ class Collection { this.error = {label, body} }) } - - /** - * Gets the ids of all the items in the collection - */ - @computed get ids (): Array { - const ids = this.models.map((item) => item.id) - .filter(Boolean) - - // LOL flow: https://github.com/facebook/flow/issues/1414 - return ((ids.filter(Boolean): Array): Array) - } } export default Collection