1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 08:56:38 +02:00

Load discussion and posts with one request

Speeds things up a heap.
Also fix a whole bunch of bugs with the post stream.
This commit is contained in:
Toby Zerner
2015-02-06 10:30:38 +10:30
parent bc3aa449e7
commit 0365ae6c71
13 changed files with 279 additions and 164 deletions

View File

@@ -11,58 +11,37 @@ export default Ember.View.extend(Ember.Evented, {
sidebarItems: null,
loadingNumber: false,
didInsertElement: function() {
// Create and populate an array of items to be rendered in the sidebar.
var sidebarItems = TaggedArray.create();
this.trigger('populateSidebar', sidebarItems);
this.set('sidebarItems', sidebarItems);
// By this stage the discussion controller has initialized the post
// stream object, and there may or may not be posts loaded into it.
// Either way, we want to tell our stream content component to jump
// down to the start position specified in the controller's query
// params.
this.loadStreamContentForNewDiscussion();
// For that matter, whenever the controller's start query param
// changes, we want to tell our stream content component to jump down
// to it.
this.get('controller').on('startWasChanged', this, this.goToNumber);
this.get('streamContent').on('loadedNumber', this, this.loadedNumber);
this.get('controller').on('loaded', this, this.loaded);
this.get('controller').on('startWasChanged', this, this.startWasChanged);
},
willDestroyElement: function() {
this.get('controller').off('startWasChanged', this, this.goToNumber);
this.get('streamContent').off('loadedNumber', this, this.loadedNumber);
this.get('controller').off('loaded', this, this.loaded);
this.get('controller').off('startWasChanged', this, this.startWasChanged);
},
goToNumber: function(start) {
// We can only proceed if the controller has loaded the discussion
// details and the view has been rendered.
if (this.get('controller.loaded') && this.get('streamContent') && ! this.get('loadingNumber')) {
this.get('streamContent').send('goToNumber', start);
this.set('loadingNumber', true);
}
// When the controller has finished loading, we want to scroll down to the
// appropriate post instantly (without animation).
loaded: function() {
this.get('streamContent').send('goToNumber', this.get('controller.start'), true);
},
loadedNumber: function() {
this.set('loadingNumber', false);
// When the start position of the discussion changes, we want to scroll
// down to the appropriate post.
startWasChanged: function(start) {
this.get('streamContent').send('goToNumber', start);
},
// ------------------------------------------------------------------------
// OBSERVERS
// ------------------------------------------------------------------------
// Whenever the controller has switched out the old discussion model for a
// new one, we want to begin loading posts according to the ?start param.
loadStreamContentForNewDiscussion: function() {
if (this.get('controller.loaded')) {
this.goToNumber(this.get('controller.start'));
}
}.observes('controller.loaded'),
// Whenever the model's title changes, we want to update that document's
// title the reflect the new title.
updateTitle: function() {