Skip to content

Instantly share code, notes, and snippets.

@zourtney
Forked from jhunken/decorator
Last active March 18, 2016 02:30
Show Gist options
  • Save zourtney/dcd8914d68b31a4f1f39 to your computer and use it in GitHub Desktop.
Save zourtney/dcd8914d68b31a4f1f39 to your computer and use it in GitHub Desktop.
.config(['$provide', function($provide) {
// Minification-safe hack.
var $$watchers = '$$watchers',
$$nextSibling = '$$nextSibling',
$$childHead = '$$childHead',
$$childTail = '$$childTail',
$$listeners = '$$listeners',
$$listenerCount = '$$listenerCount',
$id = '$id',
$$childScopeClass = '$$childScopeClass',
$parent = '$parent',
$$prevSibling = '$$prevSibling';
$provide.decorator('$rootScope', ['$delegate', function($rootScope) {
var proto = Object.getPrototypeOf($rootScope);
function nextUid () {
return ++$rootScope.$id;
}
proto.$new = function(isolate) {
var child;
if (isolate) {
child = new proto.constructor();
child.$root = this.$root;
// ensure that there is just one async queue per $rootScope and its children
child.$$asyncQueue = this.$$asyncQueue;
child.$$postDigestQueue = this.$$postDigestQueue;
} else {
// Only create a child scope class if somebody asks for one,
// but cache it to allow the VM to optimize lookups.
if (!this.$$childScopeClass) {
this.$$childScopeClass = function() {
this[$$watchers] = this[$$nextSibling] =
this[$$childHead] = this[$$childTail] = null;
this[$$listeners] = {};
this[$$listenerCount] = {};
this[$id] = nextUid();
this[$$childScopeClass] = null;
};
this.$$childScopeClass.prototype = this;
}
child = new this.$$childScopeClass();
}
child['this'] = child;
child[$parent] = this;
child[$$prevSibling] = this.$$childTail;
if (this.$$childHead) {
this.$$childTail.$$nextSibling = child;
this.$$childTail = child;
} else {
this.$$childHead = this.$$childTail = child;
}
return child;
};
$rootScope.$new = proto.$new;
return $rootScope;
}]);
}]);
@dac09
Copy link

dac09 commented May 20, 2015

Thank you for this, has worked for me (from preliminary testing).

@JobaDiniz
Copy link

Is this work against Angular 1.2.28?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment