Remove duplicate bufferlist storage. Only use object

This commit is contained in:
Tor Hveem 2014-02-26 19:39:48 +01:00
parent ef8a3ef343
commit bebc1c7bce
2 changed files with 16 additions and 32 deletions

View File

@ -1077,10 +1077,10 @@ weechat.directive('inputBar', function() {
code = 58; code = 58;
} }
var bufferNumber = code - 48; var bufferNumber = code - 48 - 1 ;
var activeBuffer = models.getBufferByIndex(bufferNumber); var activeBufferId = Object.keys(models.getBuffers())[bufferNumber];
if (activeBuffer) { if (activeBufferId) {
models.setActiveBuffer(activeBuffer.id); models.setActiveBuffer(activeBufferId);
$event.preventDefault(); $event.preventDefault();
} }
} }

View File

@ -327,7 +327,6 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
}; };
var BufferList = [];
var activeBuffer = null; var activeBuffer = null;
var previousBuffer = null; var previousBuffer = null;
@ -340,24 +339,9 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
* @return undefined * @return undefined
*/ */
this.addBuffer = function(buffer) { this.addBuffer = function(buffer) {
BufferList[buffer.id] = buffer;
if (BufferList.length === 1) {
activeBuffer = buffer;
}
this.model.buffers[buffer.id] = buffer; this.model.buffers[buffer.id] = buffer;
}; };
this.getBufferByIndex = function(index) {
var i = 0;
for (var v in BufferList) {
if (index === ++i) {
return BufferList[v];
}
}
};
/* /*
* Returns the current active buffer * Returns the current active buffer
* *
@ -390,11 +374,16 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
previousBuffer = this.getActiveBuffer(); previousBuffer = this.getActiveBuffer();
activeBuffer = _.find(this.model.buffers, function(buffer) { if (key === 'id') {
if (buffer[key] === bufferId) { activeBuffer = this.model.buffers[bufferId];
return buffer; }
} else {
}); activeBuffer = _.find(this.model.buffers, function(buffer) {
if (buffer[key] === bufferId) {
return buffer;
}
});
}
if (activeBuffer === undefined) { if (activeBuffer === undefined) {
// Buffer not found, undo assignment // Buffer not found, undo assignment
@ -422,14 +411,13 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
* Returns the buffer list * Returns the buffer list
*/ */
this.getBuffers = function() { this.getBuffers = function() {
return BufferList; return this.model.buffers;
}; };
/* /*
* Reinitializes the model * Reinitializes the model
*/ */
this.reinitialize = function() { this.reinitialize = function() {
BufferList = [];
this.model.buffers = {}; this.model.buffers = {};
}; };
@ -440,11 +428,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
* @return the buffer object * @return the buffer object
*/ */
this.getBuffer = function(bufferId) { this.getBuffer = function(bufferId) {
return _.find(this.model.buffers, function(buffer) { return this.model.buffers[bufferId];
if (buffer.id === bufferId) {
return buffer;
}
});
}; };
/* /*