UNPKG

@emartech/faye-redis-sharded

Version:

Redis backend engine for Faye with support for sharding

47 lines (40 loc) 1.03 kB
Faye.Set = Faye.Class({ initialize: function() { this._index = {}; }, add: function(item) { var key = (item.id !== undefined) ? item.id : item; if (this._index.hasOwnProperty(key)) return false; this._index[key] = item; return true; }, forEach: function(block, context) { for (var key in this._index) { if (this._index.hasOwnProperty(key)) block.call(context, this._index[key]); } }, isEmpty: function() { for (var key in this._index) { if (this._index.hasOwnProperty(key)) return false; } return true; }, member: function(item) { for (var key in this._index) { if (this._index[key] === item) return true; } return false; }, remove: function(item) { var key = (item.id !== undefined) ? item.id : item; var removed = this._index[key]; delete this._index[key]; return removed; }, toArray: function() { var array = []; this.forEach(function(item) { array.push(item) }); return array; } });