diff --git a/packages/xo-lib/package.json b/packages/xo-lib/package.json index 0d7d1bb73..45f3914e5 100644 --- a/packages/xo-lib/package.json +++ b/packages/xo-lib/package.json @@ -33,7 +33,7 @@ "make-error": "^0.3.0", "pw": "0.0.4", "ws": "^0.7.1", - "xo-collection": "^0.2.1" + "xo-collection": "^0.3.0" }, "devDependencies": { "mocha": "^2.1.0", diff --git a/packages/xo-lib/xo.js b/packages/xo-lib/xo.js index fc8d6b4f3..2ee6cf5fd 100644 --- a/packages/xo-lib/xo.js +++ b/packages/xo-lib/xo.js @@ -8,6 +8,7 @@ var forEach = require('lodash.foreach') var Index = require('xo-collection/index') var isString = require('lodash.isstring') var startsWith = require('lodash.startswith') +var UniqueIndex = require('xo-collection/unique-index') var Api = require('./api') var BackOff = require('./back-off') @@ -62,7 +63,9 @@ function setMultiple (collection, items) { function unsetMultiple (collection, items) { forEach(items, function (item) { - collection.unset(item) + if (collection.has(item)) { + collection.remove(item) + } }) } @@ -111,9 +114,15 @@ function Xo (opts) { objects.getKey = function (item) { return item.UUID || item.ref || 'undefined' } - objects.createIndex('ref', new Index('ref')) + objects.createIndex('ref', new UniqueIndex('ref')) objects.createIndex('type', new Index('type')) - objects.createIndex('uuid', new Index('uuid')) + objects.createIndex('UUID', new UniqueIndex('UUID')) + + // This hack is used to trigger an Angular refresh in xo-web + // every time the collection is updated. + objects.on('finish', function () { + Bluebird.resolve().then(function () {}) + }) this.status = 'disconnected' this.user = null