mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-28 11:26:16 -04:00
docs for AttributePool
This commit is contained in:
parent
86af7c7f1b
commit
379689c794
1 changed files with 24 additions and 5 deletions
|
@ -23,17 +23,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
An AttributePool maintains a mapping from [key,value] Pairs called
|
* An AttributePool maintains a mapping from [key,value] Pairs called
|
||||||
Attributes to Numbers (unsigened integers) and vice versa. These numbers are
|
* Attributes to Numbers (unsigened integers) and vice versa. These numbers are
|
||||||
used to reference Attributes in Changesets.
|
* used to reference Attributes in Changesets.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var AttributePool = function () {
|
var AttributePool = function () {
|
||||||
this.numToAttrib = {}; // e.g. {0: ['foo','bar']}
|
this.numToAttrib = {}; // e.g. {0: ['foo','bar']}
|
||||||
this.attribToNum = {}; // e.g. {'foo,bar': 0}
|
this.attribToNum = {}; // e.g. {'foo,bar': 0}
|
||||||
this.nextNum = 0;
|
this.nextNum = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param {Array<string,string>} attrib
|
||||||
|
* @param {boolean} dontAddIfAbsent if true a non-existent attribute won't be added
|
||||||
|
* @return {number} id of the attribute
|
||||||
|
*/
|
||||||
AttributePool.prototype.putAttrib = function (attrib, dontAddIfAbsent) {
|
AttributePool.prototype.putAttrib = function (attrib, dontAddIfAbsent) {
|
||||||
var str = String(attrib);
|
var str = String(attrib);
|
||||||
if (str in this.attribToNum) {
|
if (str in this.attribToNum) {
|
||||||
|
@ -48,6 +52,10 @@ AttributePool.prototype.putAttrib = function (attrib, dontAddIfAbsent) {
|
||||||
return num;
|
return num;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param {number} num the id of the attribute
|
||||||
|
* @return {Array<string,string>|undefined} an attribute
|
||||||
|
*/
|
||||||
AttributePool.prototype.getAttrib = function (num) {
|
AttributePool.prototype.getAttrib = function (num) {
|
||||||
var pair = this.numToAttrib[num];
|
var pair = this.numToAttrib[num];
|
||||||
if (!pair) {
|
if (!pair) {
|
||||||
|
@ -56,18 +64,29 @@ AttributePool.prototype.getAttrib = function (num) {
|
||||||
return [pair[0], pair[1]]; // return a mutable copy
|
return [pair[0], pair[1]]; // return a mutable copy
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param {number} num the id of the attribute
|
||||||
|
* @return {string} the attribute's key name
|
||||||
|
*/
|
||||||
AttributePool.prototype.getAttribKey = function (num) {
|
AttributePool.prototype.getAttribKey = function (num) {
|
||||||
var pair = this.numToAttrib[num];
|
var pair = this.numToAttrib[num];
|
||||||
if (!pair) return '';
|
if (!pair) return '';
|
||||||
return pair[0];
|
return pair[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param {number} num the id of the attribute
|
||||||
|
* @return {string} the attribute's value
|
||||||
|
*/
|
||||||
AttributePool.prototype.getAttribValue = function (num) {
|
AttributePool.prototype.getAttribValue = function (num) {
|
||||||
var pair = this.numToAttrib[num];
|
var pair = this.numToAttrib[num];
|
||||||
if (!pair) return '';
|
if (!pair) return '';
|
||||||
return pair[1];
|
return pair[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param {function} func a function to be called on every attribute pair
|
||||||
|
*/
|
||||||
AttributePool.prototype.eachAttrib = function (func) {
|
AttributePool.prototype.eachAttrib = function (func) {
|
||||||
for (var n in this.numToAttrib) {
|
for (var n in this.numToAttrib) {
|
||||||
var pair = this.numToAttrib[n];
|
var pair = this.numToAttrib[n];
|
||||||
|
@ -93,4 +112,4 @@ AttributePool.prototype.fromJsonable = function (obj) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = AttributePool;
|
module.exports = AttributePool;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue