stream fetch new no rebuild fix
This commit is contained in:
@@ -42,14 +42,19 @@ define('collections/note', 'collection', function (Dep) {
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
fetchNew: function (options) {
|
||||
var options = options || {};
|
||||
options = options || {};
|
||||
|
||||
options.data = options.data || {};
|
||||
|
||||
options.fetchNew = true;
|
||||
options.noRebuild = true;
|
||||
options.lengthBeforeFetch = this.length;
|
||||
|
||||
if (this.length) {
|
||||
options.data.after = this.models[0].get('createdAt');
|
||||
options.remove = false;
|
||||
@@ -57,9 +62,8 @@ define('collections/note', 'collection', function (Dep) {
|
||||
options.maxSize = null;
|
||||
}
|
||||
|
||||
this.fetch(options);
|
||||
return this.fetch(options);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -30,32 +30,36 @@ define('views/notification/record/list', 'views/record/list-expanded', function
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
showNewRecords: function () {
|
||||
var collection = this.collection;
|
||||
var initialCount = collection.length;
|
||||
setup: function () {
|
||||
Dep.prototype.setup.call(this);
|
||||
|
||||
var $list = this.$el.find(this.listContainerEl);
|
||||
|
||||
var success = () => {
|
||||
if (initialCount === 0) {
|
||||
this.reRender();
|
||||
|
||||
this.listenTo(this.collection, 'sync', (c, r, options) => {
|
||||
if (!options.fetchNew) {
|
||||
return;
|
||||
}
|
||||
|
||||
var rowCount = collection.length - initialCount;
|
||||
var rowsReady = 0;
|
||||
let lengthBeforeFetch = options.lengthBeforeFetch || 0;
|
||||
|
||||
for (var i = rowCount - 1; i >= 0; i--) {
|
||||
var model = collection.at(i);
|
||||
if (lengthBeforeFetch === 0) {
|
||||
this.reRender();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let $list = this.$el.find(this.listContainerEl);
|
||||
|
||||
let rowCount = this.collection.length - lengthBeforeFetch;
|
||||
|
||||
for (let i = rowCount - 1; i >= 0; i--) {
|
||||
let model = this.collection.at(i);
|
||||
|
||||
this.buildRow(i, model, view => {
|
||||
view.getHtml(html => {
|
||||
var $row = $(this.getRowContainerHtml(model.id));
|
||||
let $row = $(this.getRowContainerHtml(model.id));
|
||||
|
||||
$row.append(html);
|
||||
$list.prepend($row);
|
||||
rowsReady++;
|
||||
|
||||
view._afterRender();
|
||||
|
||||
if (view.options.el) {
|
||||
@@ -64,13 +68,11 @@ define('views/notification/record/list', 'views/record/list-expanded', function
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.noRebuild = true;
|
||||
};
|
||||
|
||||
collection.fetchNew({
|
||||
success: success,
|
||||
});
|
||||
},
|
||||
|
||||
showNewRecords: function () {
|
||||
this.collection.fetchNew();
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1616,6 +1616,12 @@ define(
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.noRebuild) {
|
||||
this.noRebuild = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.checkedList = [];
|
||||
|
||||
this.allResultIsChecked = false;
|
||||
@@ -2225,6 +2231,7 @@ define(
|
||||
}
|
||||
});
|
||||
|
||||
// If using promise callback, then need to pass `noRebuild: true`.
|
||||
collection.fetch({
|
||||
success: success,
|
||||
remove: false,
|
||||
|
||||
@@ -38,6 +38,43 @@ define('views/stream/record/list', 'views/record/list-expanded', function (Dep)
|
||||
this.itemViews = this.getMetadata().get('clientDefs.Note.itemViews') || {};
|
||||
|
||||
Dep.prototype.setup.call(this);
|
||||
|
||||
this.listenTo(this.collection, 'sync', (c, r, options) => {
|
||||
if (!options.fetchNew) {
|
||||
return;
|
||||
}
|
||||
|
||||
let lengthBeforeFetch = options.lengthBeforeFetch || 0;
|
||||
|
||||
if (lengthBeforeFetch === 0) {
|
||||
this.reRender();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let $list = this.$el.find(this.listContainerEl);
|
||||
|
||||
let rowCount = this.collection.length - lengthBeforeFetch;
|
||||
|
||||
for (let i = rowCount - 1; i >= 0; i--) {
|
||||
let model = this.collection.at(i);
|
||||
|
||||
this.buildRow(i, model, view => {
|
||||
view.getHtml(html => {
|
||||
let $row = $(this.getRowContainerHtml(model.id));
|
||||
|
||||
$row.append(html);
|
||||
$list.prepend($row);
|
||||
|
||||
view._afterRender();
|
||||
|
||||
if (view.options.el) {
|
||||
view.setElement(view.options.el);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
buildRow: function (i, model, callback) {
|
||||
@@ -89,60 +126,19 @@ define('views/stream/record/list', 'views/record/list-expanded', function (Dep)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
|
||||
this.trigger('after:build-rows');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
|
||||
this.trigger('after:build-rows');
|
||||
}
|
||||
},
|
||||
|
||||
showNewRecords: function () {
|
||||
var collection = this.collection;
|
||||
var initialCount = collection.length;
|
||||
|
||||
var $list = this.$el.find(this.listContainerEl);
|
||||
|
||||
var success = () => {
|
||||
if (initialCount === 0) {
|
||||
this.reRender();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var rowCount = collection.length - initialCount;
|
||||
var rowsReady = 0;
|
||||
|
||||
for (var i = rowCount - 1; i >= 0; i--) {
|
||||
var model = collection.at(i);
|
||||
|
||||
this.buildRow(i, model, (view) => {
|
||||
view.getHtml((html) => {
|
||||
var $row = $(this.getRowContainerHtml(model.id));
|
||||
|
||||
$row.append(html);
|
||||
$list.prepend($row);
|
||||
|
||||
rowsReady++;
|
||||
|
||||
view._afterRender();
|
||||
|
||||
if (view.options.el) {
|
||||
view.setElement(view.options.el);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.noRebuild = true;
|
||||
};
|
||||
|
||||
collection.fetchNew({
|
||||
success: success,
|
||||
});
|
||||
this.collection.fetchNew();
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user