Skip to content

Commit

Permalink
bugfix(moved-to): Added missing callback and handler for moving items…
Browse files Browse the repository at this point in the history
… inside a collection
  • Loading branch information
dotansimha committed Oct 25, 2016
1 parent 24dc190 commit e79af51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions dist/ObservableCursor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export declare class ObservableCursor<T> extends Observable<T[]> {
_addedAt(doc: any, at: any, before: any): void;
_changedAt(doc: any, old: any, at: any): void;
_removedAt(doc: any, at: any): void;
_movedTo(doc: any, fromIndex: any, toIndex: any): void;
_handleChange(): void;
_observeCursor(cursor: Mongo.Cursor<T>): any;
}
8 changes: 8 additions & 0 deletions dist/ObservableCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export var ObservableCursor = (function (_super) {
if (this._hCursor) {
this._hCursor.stop();
}
this._data = [];
this._hCursor = null;
};
ObservableCursor.prototype.dispose = function () {
Expand Down Expand Up @@ -77,6 +78,12 @@ export var ObservableCursor = (function (_super) {
this._handleChange();
};
;
ObservableCursor.prototype._movedTo = function (doc, fromIndex, toIndex) {
this._data.splice(fromIndex, 1);
this._data.splice(toIndex, 0, doc);
this._handleChange();
};
;
ObservableCursor.prototype._handleChange = function () {
var _this = this;
this._zone.run(function () {
Expand All @@ -89,6 +96,7 @@ export var ObservableCursor = (function (_super) {
return gZone.run(function () { return cursor.observe({
addedAt: _this._addedAt.bind(_this),
changedAt: _this._changedAt.bind(_this),
movedTo: _this._movedTo.bind(_this),
removedAt: _this._removedAt.bind(_this)
}); });
};
Expand Down
8 changes: 8 additions & 0 deletions dist/bundles/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var ObservableCursor = (function (_super) {
if (this._hCursor) {
this._hCursor.stop();
}
this._data = [];
this._hCursor = null;
};
ObservableCursor.prototype.dispose = function () {
Expand Down Expand Up @@ -132,6 +133,12 @@ var ObservableCursor = (function (_super) {
this._handleChange();
};

ObservableCursor.prototype._movedTo = function (doc, fromIndex, toIndex) {
this._data.splice(fromIndex, 1);
this._data.splice(toIndex, 0, doc);
this._handleChange();
};

ObservableCursor.prototype._handleChange = function () {
var _this = this;
this._zone.run(function () {
Expand All @@ -144,6 +151,7 @@ var ObservableCursor = (function (_super) {
return gZone.run(function () { return cursor.observe({
addedAt: _this._addedAt.bind(_this),
changedAt: _this._changedAt.bind(_this),
movedTo: _this._movedTo.bind(_this),
removedAt: _this._removedAt.bind(_this)
}); });
};
Expand Down
7 changes: 7 additions & 0 deletions src/ObservableCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export class ObservableCursor<T> extends Observable<T[]> {
this._handleChange();
};

_movedTo(doc, fromIndex, toIndex) {
this._data.splice(fromIndex, 1);
this._data.splice(toIndex, 0, doc);
this._handleChange();
};

_handleChange() {
this._zone.run(() => {
this._runNext(this._data);
Expand All @@ -103,6 +109,7 @@ export class ObservableCursor<T> extends Observable<T[]> {
() => cursor.observe({
addedAt: this._addedAt.bind(this),
changedAt: this._changedAt.bind(this),
movedTo: this._movedTo.bind(this),
removedAt: this._removedAt.bind(this)
}));
}
Expand Down

0 comments on commit e79af51

Please sign in to comment.