Browse files

Merge branch 'master' of github.com:SitePen/dstore

  • Loading branch information...
2 parents 7d1cc4a + 111a918 commit 63ca5e0945e41c0975de0be90fc6f96f15452711 @kriszyp kriszyp committed Feb 21, 2014
Showing with 33 additions and 19 deletions.
  1. +13 −1 Store.js
  2. +9 −9 tests/Store.js
  3. +11 −9 tests/all.js
View
14 Store.js
@@ -158,8 +158,20 @@ define([
},
range: function (start, end) {
+ if (this.ranged) {
+ var base = this.ranged.start,
+ cap = this.ranged.end;
+ // TODO: Should we quietly cap start and end? Should we warn or throw an error instead?
+ if (isFinite(cap)) {
+ start = Math.min(base + start, cap);
+ end = isFinite(end) ? Math.min(base + end, cap) : cap;
+ } else {
+ start = base + start;
+ end = isFinite(end) ? base + end : undefined;
+ }
+ }
+
return this._createSubCollection({
- // TODO: `ranged` should probably base itself on an existing `ranged` if it exitsts
ranged: { start: start, end: end }
});
}
View
18 tests/Store.js
@@ -44,15 +44,15 @@ define([
},
'range': function () {
- var expectedRange1 = { start: 10, end: 20 },
- expectedRange2 = { start: 25 },
- rangedCollection;
-
- rangedCollection = store.range(expectedRange1.start, expectedRange1.end);
- assert.deepEqual(rangedCollection.ranged, expectedRange1);
-
- rangedCollection = rangedCollection.range(expectedRange2.start);
- assert.deepEqual(rangedCollection.ranged, { start: expectedRange2.start, end: undefined });
+ var rangedCollection = store.range(100);
+ assert.deepEqual(rangedCollection.ranged, { start: 100, end: undefined });
+ rangedCollection = rangedCollection.range(25, 50);
+ assert.deepEqual(rangedCollection.ranged, { start: 125, end: 150 });
+
+ rangedCollection = store.range(100, 200);
+ assert.deepEqual(rangedCollection.ranged, { start: 100, end: 200 });
+ rangedCollection = rangedCollection.range(25);
+ assert.deepEqual(rangedCollection.ranged, { start: 125, end: 200 });
}
// TODO: Add map test and tests for other Store features
View
20 tests/all.js
@@ -1,16 +1,18 @@
define([
- 'intern/node_modules/dojo/has!host-browser?./Model',
- 'intern/node_modules/dojo/has!host-browser?./Memory',
+ './Store',
+ './Model',
+ './Memory',
+ // TODO: Examing the following has!host-browser checks to see if the tests can be made to run outside of a browser
'intern/node_modules/dojo/has!host-browser?./Rest',
- 'intern/node_modules/dojo/has!host-browser?./Observable',
+ './Observable',
'intern/node_modules/dojo/has!host-browser?./Cache',
'intern/node_modules/dojo/has!host-browser?./Csv',
'intern/node_modules/dojo/has!host-browser?./rql',
- 'intern/node_modules/dojo/has!host-browser?./validating',
- 'intern/node_modules/dojo/has!host-browser?./validators',
- 'intern/node_modules/dojo/has!host-browser?./legacy/DstoreAdapter-Memory',
- 'intern/node_modules/dojo/has!host-browser?./charting/StoreSeries',
- 'intern/node_modules/dojo/has!host-browser?./legacy/StoreAdapter-Memory',
+ './validating',
+ './validators',
+ './legacy/DstoreAdapter-Memory',
+ './charting/StoreSeries',
+ './legacy/StoreAdapter-Memory',
'intern/node_modules/dojo/has!host-browser?./legacy/StoreAdapter-JsonRest'
], function () {
-});
+});

0 comments on commit 63ca5e0

Please sign in to comment.