// ========================================================================== // Project: SproutCore Costello - Property Observing Library // Copyright: ©2006-2011 Strobe Inc. and contributors. // Portions ©2008-2011 Apple Inc. All rights reserved. // License: Licensed under MIT license (see license.js) // ========================================================================== /** @class A RangeObserver is used by Arrays to automatically observe all of the objects in a particular range on the array. Whenever any property on one of those objects changes, it will notify its delegate. Likewise, whenever the contents of the array itself changes, it will notify its delegate and possibly update its own registration. This implementation uses only SC.Array methods. It can be used on any object that complies with SC.Array. You may, however, choose to subclass this object in a way that is more optimized for your particular design. @since SproutCore 1.0 */ SC.RangeObserver = /** @scope SC.RangeObserver.prototype */{ /** Walk like a duck. @property {Boolean} */ isRangeObserver: YES, /** @private */ toString: function() { var base = this.indexes ? this.indexes.toString() : "SC.IndexSet<..>"; return base.replace('IndexSet', 'RangeObserver(%@)'.fmt(SC.guidFor(this))); }, /** Creates a new range observer owned by the source. The indexSet you pass must identify the indexes you are interested in observing. The passed target/method will be invoked whenever the observed range changes. Note that changes to a range are buffered until the end of a run loop unless a property on the record itself changes. @param {SC.Array} source the source array @param {SC.IndexSet} indexSet set of indexes to observer @param {Object} target the target @param {Function|String} method the method to invoke @param {Object} context optional context to include in callback @param {Boolean} isDeep if YES, observe property changes as well @returns {SC.RangeObserver} instance */ create: function(source, indexSet, target, method, context, isDeep) { var ret = SC.beget(this); ret.source = source; ret.indexes = indexSet ? indexSet.frozenCopy() : null; ret.target = target; ret.method = method; ret.context = context ; ret.isDeep = isDeep || false ; ret.beginObserving(); return ret ; }, /** Create subclasses for the RangeObserver. Pass one or more attribute hashes. Use this to create customized RangeObservers if needed for your classes. @param {Hash} attrs one or more attribute hashes @returns {SC.RangeObserver} extended range observer class */ extend: function(attrs) { var ret = SC.beget(this), args = arguments; for(var i=0, l=args.length; i