Merge pull request #192 from torhve/clean-bufferlist

Remove duplicate bufferlist storage. Only use object
This commit is contained in:
David Cormier 2014-02-27 08:08:13 -05:00
commit 69292d0088
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();
if (key === 'id') {
activeBuffer = this.model.buffers[bufferId];
}
else {
activeBuffer = _.find(this.model.buffers, function(buffer) { activeBuffer = _.find(this.model.buffers, function(buffer) {
if (buffer[key] === bufferId) { if (buffer[key] === bufferId) {
return buffer; 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;
}
});
}; };
/* /*