1 decade ago by KonTrax
Hello, Being new to the ImpactJS community I thought I'll start by contributing with a little bit of code.
I needed a quick way to communicate between objects on a per update basis and wrote an object to keep track of states without constantly needing to define everything to avoid errors and warnings. Nothing fancy just a quick solution that takes care of incompatibilities.
Will probably be updating it so I add the jsfiddle. Oh and it's not packed as a module due to jsfiddle.
jsfiddle link
(edit: updated the code) 19.01.13
I needed a quick way to communicate between objects on a per update basis and wrote an object to keep track of states without constantly needing to define everything to avoid errors and warnings. Nothing fancy just a quick solution that takes care of incompatibilities.
Will probably be updating it so I add the jsfiddle. Oh and it's not packed as a module due to jsfiddle.
jsfiddle link
window.ig.Bob = function(){ this.current = {}; this.log = {}; };window.ig.Bob.prototype = { // Set to true / specified value set: function( name, value ){ this.current[name] = typeof value !== 'undefined' ? value : true; }, // Set to oposite of log toggle: function( name ){ if(typeof this.log[name] === 'undefined') this.current[name] = true; }, // Use logged value repeat: function( name ){ if(typeof this.log[name] !== 'undefined') this.current[name] = this.log[name]; }, // Get value get: function( name ){ return typeof this.current[name] !== 'undefined' ? this.current[name] : false; }, // Check if true chk: function( name ){ return (typeof this.current[name] !== 'undefined') }, // Get log value lget: function( name ){ return typeof this.log[name] !== 'undefined' ? this.log[name] : false; }, // Check log if true lchk: function( name ){ return (typeof this.log[name] !== 'undefined') }, // Get full list getAll: function( ){ return this.current; }, // Get full log getLog: function( ){ return this.log; }, // Log and reset current reset: function( ){ this.clean(this.log); /**/ this.copy(this.current, this.log); /**/ this.clean(this.current); /**/ }, // Clean object clean: function( obj ){ for (var p in obj) /**/ if(typeof obj[p] !== 'undefined') /**/ delete obj[p]; /**/ }, // Copy object copy: function( source, target ){ for(var k in source) /**/ target[k]=source[k]; /**/ }, // Count object for debug count: function( countlog ){ var i = 0; if(countlog) for(var k in this.log) i++; else for(var k in this.current) i++; return i; } };
(edit: updated the code) 19.01.13