Merge pull request #192 from torhve/clean-bufferlist
Remove duplicate bufferlist storage. Only use object
This commit is contained in:
commit
69292d0088
2 changed files with 16 additions and 32 deletions
|
@ -1077,10 +1077,10 @@ weechat.directive('inputBar', function() {
|
|||
code = 58;
|
||||
}
|
||||
|
||||
var bufferNumber = code - 48;
|
||||
var activeBuffer = models.getBufferByIndex(bufferNumber);
|
||||
if (activeBuffer) {
|
||||
models.setActiveBuffer(activeBuffer.id);
|
||||
var bufferNumber = code - 48 - 1 ;
|
||||
var activeBufferId = Object.keys(models.getBuffers())[bufferNumber];
|
||||
if (activeBufferId) {
|
||||
models.setActiveBuffer(activeBufferId);
|
||||
$event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
|
30
js/models.js
30
js/models.js
|
@ -327,7 +327,6 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
|||
};
|
||||
|
||||
|
||||
var BufferList = [];
|
||||
var activeBuffer = null;
|
||||
var previousBuffer = null;
|
||||
|
||||
|
@ -340,24 +339,9 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
|||
* @return undefined
|
||||
*/
|
||||
this.addBuffer = function(buffer) {
|
||||
BufferList[buffer.id] = buffer;
|
||||
if (BufferList.length === 1) {
|
||||
activeBuffer = 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
|
||||
*
|
||||
|
@ -390,11 +374,16 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
|||
|
||||
previousBuffer = this.getActiveBuffer();
|
||||
|
||||
if (key === 'id') {
|
||||
activeBuffer = this.model.buffers[bufferId];
|
||||
}
|
||||
else {
|
||||
activeBuffer = _.find(this.model.buffers, function(buffer) {
|
||||
if (buffer[key] === bufferId) {
|
||||
return buffer;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (activeBuffer === undefined) {
|
||||
// Buffer not found, undo assignment
|
||||
|
@ -422,14 +411,13 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
|||
* Returns the buffer list
|
||||
*/
|
||||
this.getBuffers = function() {
|
||||
return BufferList;
|
||||
return this.model.buffers;
|
||||
};
|
||||
|
||||
/*
|
||||
* Reinitializes the model
|
||||
*/
|
||||
this.reinitialize = function() {
|
||||
BufferList = [];
|
||||
this.model.buffers = {};
|
||||
};
|
||||
|
||||
|
@ -440,11 +428,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
|||
* @return the buffer object
|
||||
*/
|
||||
this.getBuffer = function(bufferId) {
|
||||
return _.find(this.model.buffers, function(buffer) {
|
||||
if (buffer.id === bufferId) {
|
||||
return buffer;
|
||||
}
|
||||
});
|
||||
return this.model.buffers[bufferId];
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue