1 rio.Id = Class.create({ 2 initialize: function(id) { 3 if (id) { 4 this._val = id; 5 this._temporary = false; 6 } else { 7 this._val = (Math.random() * -1000000000).round(); 8 this._temporary = true; 9 } 10 this._cacheKey = this._val; 11 this._todos = []; 12 }, 13 14 temporary: function() { 15 return this._temporary; 16 }, 17 18 cacheKey: function() { 19 return this._cacheKey; 20 }, 21 22 reify: function(realId) { 23 if (!this._temporary) { return; } 24 this._val = realId; 25 this._temporary = false; 26 this._todos.each(function(todo) { todo(); }); 27 }, 28 29 doAfterReification: function(todo) { 30 if(!this._temporary) {todo();} 31 this._todos.push(todo); 32 }, 33 34 toString: function() { 35 return this._val.toString(); 36 }, 37 38 value: function() { 39 return this._val; 40 } 41 }); 42 43 rio.Id.toString = function() { return "Id"; };