Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit c2346273138ffa25355ac084a99a23e7e6f95f76 2 parents e46cd6b + 20c6d59
@kriszyp kriszyp authored
Showing with 53 additions and 6 deletions.
  1. +8 −4 Observable.js
  2. +45 −2 tests/Observable.js
View
12 Observable.js
@@ -94,7 +94,11 @@ define([
);
}
- var observed = this._createSubCollection({
+ // delegate rather than call _createSubCollection because we are not ultimately creating
+ // a new collection, just decorating an existing collection with item index tracking.
+ // If we use _createSubCollection, it will return a new collection that may exclude
+ // important, defining properties from the tracked collection.
+ var observed = lang.delegate(this, {
// Any sub-collections created from the tracked collection should be based on this
// parent collection instead
_createSubCollection: lang.hitch(this, '_createSubCollection'),
@@ -121,7 +125,7 @@ define([
};
var ranges = [];
- if (this.hasOwnProperty('data')) {
+ if (this.data) {
observed.data = this.data.slice(0); // make local copy
// Treat in-memory data as one range to allow a single code path for all stores
registerRange(ranges, 0, observed.data.length);
@@ -245,7 +249,7 @@ define([
} else {
// we don't have a queryEngine, so we can't provide any information
// about where it was inserted or moved to. If it is an update, we leave
- // its position alone. other we at least indicate a new object
+ // its position alone. otherwise, we at least indicate a new object
if (type === 'update') {
insertedInto = removedFrom;
@@ -257,7 +261,7 @@ define([
for (i = 0; insertionRangeIndex === -1 && i < ranges.length; ++i) {
range = ranges[i];
- if (range.start <= insertedInto && insertedInto < (range.start + range.count)) {
+ if (range.start <= insertedInto && insertedInto <= (range.start + range.count)) {
insertionRangeIndex = i;
}
}
View
47 tests/Observable.js
@@ -376,8 +376,7 @@ define([
headTrimmingRange = { start: 50, end: 60 },
tailTrimmingRange = { start: 90, end: 100 };
- var observations = [],
- trackedStore = store.track(),
+ var trackedStore = store.track(),
assertRangeDefined = function (start, end) {
for(var i = start; i < end; ++i) {
assert.notEqual(trackedStore.partialData[i], undefined);
@@ -449,6 +448,50 @@ define([
});
},
+ 'new item in empty store - with queryExecutor': function () {
+ var store = new MyStore({ data: [] }),
+ collection = store.filter({ type: 'test-item' }).track();
+
+ var actualEvent;
+ collection.on('add', function (event) {
+ actualEvent = event;
+ });
+
+ var expectedTarget = collection.add({
+ type: 'test-item',
+ id: 1,
+ name: 'one'
+ });
+
+ assert.deepEqual(actualEvent, {
+ type: 'add',
+ index: 0,
+ target: expectedTarget
+ });
+ },
+
+ 'new item in empty store - without queryExecutor': function () {
+ var store = new MyStore({ data: [] }),
+ collection = store.track();
+
+ var actualEvent;
+ collection.on('add', function (event) {
+ actualEvent = event;
+ });
+
+ var expectedTarget = collection.add({
+ type: 'test-item',
+ id: 1,
+ name: 'one'
+ });
+
+ assert.deepEqual(actualEvent, {
+ type: 'add',
+ index: 0,
+ target: expectedTarget
+ });
+ },
+
'type': function () {
assert.isFalse(store === store.track(function () {}));
},
Please sign in to comment.
Something went wrong with that request. Please try again.