// ========================================================================== // Project: SproutCore Costello - Property Observing Library // Copyright: ©2006-2011 Strobe Inc. and contributors. // Portions ©2008-2010 Apple Inc. All rights reserved. // License: Licensed under MIT license (see license.js) // ========================================================================== // ........................................................................ // ObserverSet // /** @namespace This private class is used to store information about obversers on a particular key. Note that this object is not observable. You create new instances by calling SC.beget(SC.ObserverSet) ; @since SproutCore 1.0 */ SC.ObserverSet = { /** Adds the named target/method observer to the set. The method must be a function, not a string. Note that in debugging mode only, this method is overridden to also record the name of the object and function that resulted in the target/method being added. */ add: function(target, method, context) { var targetGuid = SC.guidFor(target), methodGuid = SC.guidFor(method); var targets = this._members, members = this.members; // get the set of methods var indexes = targets[targetGuid]; if ( !indexes ) indexes = targets[targetGuid] = {}; if (indexes[methodGuid] === undefined) indexes[methodGuid] = members.length; else return; members.push([target, method, context]); }, /** removes the named target/method observer from the set. If this is the last method for the named target, then the number of targets will also be reduced. returns YES if the items was removed, NO if it was not found. */ remove: function(target, method) { var targetGuid = SC.guidFor(target), methodGuid = SC.guidFor(method); var indexes = this._members[targetGuid], members = this.members; if( !indexes ) return false; var index = indexes[methodGuid]; if ( index === undefined) return false; if (index !== members.length - 1) { var entry = (members[index] = members[members.length - 1]); this._members[SC.guidFor(entry[0])][SC.guidFor(entry[1])] = index; } members.pop(); delete this._members[targetGuid][methodGuid]; return true; }, /** Invokes the target/method pairs in the receiver. Used by SC.RunLoop Note: does not support context */ invokeMethods: function() { var members = this.members, member; for( var i=0, l=members.length; i