MooTools Sets
by khrome
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/mootools/1.4.5/mootools-core-full-compat.js"></script>
<h1>Check the console</h1>
JavaScript
//Hades, a collector of things in the underworld
if(!Hades) var Hades = {};
Hades.Set = new Class({
filters : [],
filtered : false,
filteredData : [],
initialize : function(data){
this._data = data || [];
Object.defineProperty(this, 'data', {
get : function(){
if(!this.filtered){
this.filteredData = this._data;
this.filters.each(function(filter){
this.filteredData = filter.filter(this.filteredData);
}.bind(this));
this.filtered = true;
}
return this.filteredData;
}.bind(this),
set : function(value){
this._data = value;
}.bind(this)
});
},
add : function(item){
this._data.push(item);
},
remove : function(item){
if(typeOf(item) == 'number') delete this._data[item]; //todo: reindex
else this._data.remove(item);
},
addFilter : function(filter){
this.filtered = false;
this.filters.push(filter);
}
});
Hades.RemoteMongoSet = new Class({
Extends : Hades.Set,
initialize : function(data){
this._data = data || [];
Object.defineProperty(this, 'data', {
get : function(){
if(!this.filtered){
this.filteredData = this._data;
var b = TrapThatShit(testMe, [{}], this);
console.log('b', b);
this.filtered = true;
}
return this.filteredData;
}.bind(this),
set : function(value){
this._data = value;
}.bind(this)
});
}
});
var testMe = function(arg1, cb){
cb.delay(200, this, [null, [{a:'s'}]]);
}
var cloner = function(func){
try{
return (new Function(''+func.toString()));
}catch(ex){
console.log("there's a problem...