Skip to content

Instantly share code, notes, and snippets.

@krotscheck
Created October 11, 2012 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krotscheck/3874921 to your computer and use it in GitHub Desktop.
Save krotscheck/3874921 to your computer and use it in GitHub Desktop.
DCPorter Override...
/**
* This is the DCPorter Memory fix, currently hosted at
*
* https://github.com/sproutcore/sproutcore/pull/844
*/
SC.Binding.isDestroyed = NO;
SC.Binding.destroy = function() {
// If we're already destroyed, there's nothing to do.
if (this.isDestroyed)
return;
// Disconnect the binding.
this.disconnect();
// Mark it destroyed.
this.isDestroyed = YES;
// Aggressively null out internal properties. (The binding remains in some queue that I can't find just now,
// which attempts to reconnect this binding if the property paths are left intact.)
this._bindingSource = null;
this._toPropertyPath = null;
this._toPropertyKey = null;
this._toRoot = null;
this._toTarget = null;
this._fromPropertyPath = null;
this._fromPropertyKey = null;
this._fromRoot = null;
this._fromTarget = null;
this._toObserverData = null;
this._fromObserverData = null;
// Removes from the change queue.
SC.Binding._changeQueue.remove(this);
// Cancel any pending changes.
this._changePending = NO;
};
SC.tupleForPropertyPath = function(path, root) {
// if passed nothing, return nothing.
if (SC.none(path))
return null;
// if the passed path is itself a tuple, return it
if (typeof path === "object" && (path instanceof Array))
return path;
// find the key. It is the last . or first *
var key;
var stopAt = path.indexOf('*');
if (stopAt < 0)
stopAt = path.lastIndexOf('.');
key = (stopAt >= 0) ? path.slice(stopAt + 1) : path;
// convert path to object.
var obj = this.objectForPropertyPath(path, root, stopAt);
return (obj && key) ? [ obj, key ] : null;
};
SC.Object.prototype.destroy = function() {
if (this.get('isDestroyed'))
return this; // nothing to do
this.set('isDestroyed', YES);
// destroy any mixins
var idx, inits = this.destroyMixin, len = (inits) ? inits.length : 0;
for (idx = 0; idx < len; idx++)
inits[idx].call(this);
// disconnect all bindings
this.bindings.invoke('destroy');
this.bindings = null;
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment