recordset-indexer-debug.js revision 67073c302882de4baf70c80993d9120188400cd9
/**
* Provides the ability to store multiple custom hash tables referencing records in the recordset.
* This utility does not support any collision handling. New hash table entries with a used key overwrite older ones.
*
* @module recordset
* @submodule recordset-indexer
*/
function RecordsetIndexer(config) {
}
Y.mix(RecordsetIndexer, {
NS: "indexer",
NAME: "recordsetIndexer",
ATTRS: {
/**
* @description Collection of all the hashTables created by the plugin.
* The individual tables can be accessed by the key they are hashing against.
*
* @attribute hashTables
* @public
* @type object
*/
hashTables: {
value: {
}
},
keys: {
value: {
}
}
}
});
initializer: function(config) {
//setup listeners on recordset events
},
destructor: function(config) {
},
/**
* Setup the hash table for a given key with all existing records in the recordset
*
* @param key {string} A key to hash by.
* @return obj {object} The created hash table
* @method _setHashTable
* @private
*/
_setHashTable: function(key) {
for (; i<len; i++) {
}
return obj;
},
//---------------------------------------------
// Syncing Methods
//---------------------------------------------
/**
* Updates all hash tables when a record is added to the recordset
*
* @method _defAddHash
* @private
*/
_defAddHash: function(e) {
//Go through every hashtable that is stored.
//in each hashtable, look to see if the key is represented in the object being added.
//if the object being added has a key which is being stored by hashtable v, add it into the table.
}
});
});
},
/**
* Updates all hash tables when a record is removed from the recordset
*
* @method _defRemoveHash
* @private
*/
_defRemoveHash: function(e) {
//Go through every hashtable that is stored.
//in each hashtable, look to see if the key is represented in the object being deleted.
//if the hashtable has a key storing a record, and the key and the record both match the record being deleted, delete that row from the hashtable
delete v[reckey];
}
});
});
},
/**
* Updates all hash tables when the recordset is updated (a combination of add and remove)
*
* @method _defUpdateHash
* @private
*/
_defUpdateHash: function(e) {
//TODO: It will be more performant to create a new method rather than using _defAddHash, _defRemoveHash, due to the number of loops. See commented code.
e.removed = e.overwritten;
this._defAddHash(e);
this._defRemoveHash(e);
/*
var tbl = this.get('hashTables'), reckey;
Y.each(tbl, function(v, key) {
Y.each(e.updated, function(o, i) {
//delete record from hashtable if it has been overwritten
reckey = o.getValue(key);
if (reckey) {
v[reckey] = o;
}
//the undefined case is if more records are updated than currently exist in the recordset.
if (e.overwritten[i] && (v[e.overwritten[i].getValue(key)] === e.overwritten[i])) {
delete v[e.overwritten[i].getValue(key)];
}
// if (v[reckey] === o) {
// delete v[reckey];
// }
//
// //add the new updated record if it has a key that corresponds to a hash table
// if (o.getValue(key)) {
// v[o.getValue(key)] = o;
// }
});
});
*/
},
//---------------------------------------------
// Public Methods
//---------------------------------------------
/**
* Creates a new hash table.
*
* @param key {string} A key to hash by.
* @return tbls[key] {object} The created hash table
* @method createTable
* @public
*/
createTable: function(key) {
},
/**
* Get a hash table that hashes records by a given key.
*
* @param key {string} A key to hash by.
* @return table {object} The created hash table
* @method getTable
* @public
*/
}
});