Skip to content

Commit df6787e

Browse files
committed
feat($compile): add partialDigest property in directive definition
A directive asking for a child or isolated scope can now ask for that scope to have partialDigest, making any digest triggered from inside the directive only do dirty-checking for that scope and its descendants.
1 parent 8194fae commit df6787e

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/ng/compile.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
954954

955955
if (nodeLinkFn) {
956956
if (nodeLinkFn.scope) {
957-
childScope = scope.$new();
957+
childScope = scope.$new(false, nodeLinkFn.partialDigest);
958958
$node.data('$scope', childScope);
959959
} else {
960960
childScope = scope;
@@ -1368,6 +1368,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13681368
}
13691369

13701370
nodeLinkFn.scope = newScopeDirective && newScopeDirective.scope === true;
1371+
nodeLinkFn.partialDigest = nodeLinkFn.scope && newScopeDirective.partialDigest;
13711372
nodeLinkFn.transcludeOnThisElement = hasTranscludeDirective;
13721373
nodeLinkFn.templateOnThisElement = hasTemplate;
13731374
nodeLinkFn.transclude = childTranscludeFn;
@@ -1448,7 +1449,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
14481449
var LOCAL_REGEXP = /^\s*([@=&])(\??)\s*(\w*)\s*$/;
14491450
var $linkNode = jqLite(linkNode);
14501451

1451-
isolateScope = scope.$new(true);
1452+
isolateScope = scope.$new(true, newIsolateScopeDirective.partialDigest);
14521453

14531454
if (templateDirective && (templateDirective === newIsolateScopeDirective ||
14541455
templateDirective === newIsolateScopeDirective.$$originalDirective)) {

test/ng/compileSpec.js

+36
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,42 @@ describe('$compile', function() {
21672167
});
21682168
});
21692169
});
2170+
2171+
describe('partialDigest', function () {
2172+
2173+
beforeEach(module(function() {
2174+
directive('isolatePartialDigest', valueFn({
2175+
scope: {},
2176+
partialDigest: true
2177+
}));
2178+
directive('newPartialDigest', valueFn({
2179+
scope: true,
2180+
partialDigest: true
2181+
}));
2182+
}));
2183+
2184+
2185+
it('should allow you to mark an isolated scope with partialDigest', inject(
2186+
function($rootScope, $compile) {
2187+
spyOn($rootScope, '$new').andCallThrough();
2188+
2189+
expect($rootScope.$new).not.toHaveBeenCalled();
2190+
2191+
element = $compile('<div isolate-partial-digest></div>')($rootScope);
2192+
expect($rootScope.$new).toHaveBeenCalledWith(true, true);
2193+
}));
2194+
2195+
2196+
it('should allow you to mark a new scope with partialDigest', inject(
2197+
function($rootScope, $compile) {
2198+
spyOn($rootScope, '$new').andCallThrough();
2199+
2200+
expect($rootScope.$new).not.toHaveBeenCalled();
2201+
2202+
element = $compile('<div new-partial-digest></div>')($rootScope);
2203+
expect($rootScope.$new).toHaveBeenCalledWith(false, true);
2204+
}));
2205+
});
21702206
});
21712207

21722208

0 commit comments

Comments
 (0)