Comparing version 0.0.6 to 0.0.7
@@ -69,2 +69,20 @@ var Cache = require('./cache'); | ||
it('should be called everytime when data is filled into the cache, even ', function(done) { | ||
var callback = sinon.spy(); | ||
cache.subscribe('spaceships').on('data', function() { | ||
callback(); | ||
}); | ||
cache.fill([spaceship]); | ||
cache.fill([spaceship]); | ||
cache.fill([spaceship], function() { | ||
try { | ||
expect(callback).toHaveBeenCalledThrice(); | ||
done(); | ||
} catch(e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
it('should be possible to get a model from the cache by its id', function() { | ||
@@ -71,0 +89,0 @@ cache.fill([spaceship]); |
@@ -63,4 +63,5 @@ var asap = require('asap'); | ||
* @param {Array|Object} dataArr | ||
* @param {Function} cb - Callback | ||
*/ | ||
fill: function(dataArr) { | ||
fill: function(dataArr, cb) { | ||
var models = []; | ||
@@ -72,6 +73,6 @@ if(!Array.isArray(dataArr)) dataArr = [dataArr]; | ||
if(existingModel) { | ||
models.push(existingModel); | ||
return existingModel.setData(data); | ||
} | ||
var model = this._createModel(data); | ||
if(!model) return; | ||
if(!this.getCollection(collectionName)) { | ||
@@ -84,2 +85,3 @@ this._cache[collectionName] = new Collection(); | ||
this._callSubscribers(models); | ||
asap(cb); | ||
}, | ||
@@ -86,0 +88,0 @@ /** |
{ | ||
"name": "data-cache", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "cache.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57943
570