Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 48d5d62

Browse files
committed
Revert "feat(scope): Automatically $digest futures inside of $apply."
This reverts commit 46c671f. Async digest is not ready for prime-time yet.
1 parent a7e702d commit 48d5d62

File tree

6 files changed

+23
-153
lines changed

6 files changed

+23
-153
lines changed

lib/angular.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ bootstrapAngular(modules, [rootElementSelector = '[ng-app]']) {
166166
Injector injector = new Injector(modules);
167167

168168
injector.invoke((Compiler $compile, Scope $rootScope) {
169-
$rootScope.$apply(() {
170-
$compile(topElt)(injector, topElt);
171-
});
169+
$compile(topElt)(injector, topElt);
170+
$rootScope.$digest();
172171
});
173172
}

lib/block.dart

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class _ComponentFactory {
306306
attachBlockToShadowDom(BlockFactory blockFactory) {
307307
var block = blockFactory(shadowInjector);
308308
shadowDom.nodes.addAll(block.elements);
309+
shadowInjector.get(Scope).$digest();
309310
return shadowDom;
310311
}
311312

lib/directives/ng_include.dart

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class NgIncludeAttrDirective {
4747
// an url template
4848
blockCache.fromUrl(value).then((createBlock) {
4949
updateContent(createBlock);
50+
51+
// Http should take care of this
52+
scope.$digest();
5053
});
5154
}
5255
});

lib/scope.dart

+9-44
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ class Scope implements Map {
173173
}
174174

175175

176-
177-
178176
$digest() {
179177
var value, last,
180178
asyncQueue = _asyncQueue,
@@ -285,53 +283,20 @@ class Scope implements Map {
285283

286284

287285
$apply([expr]) {
288-
var toThrow;
289-
var returnValue;
290-
bool executingAsyncCallback = false;
291-
async.runZonedExperimental(() {
286+
try {
287+
_beginPhase('\$apply');
288+
return $eval(expr);
289+
} catch (e, s) {
290+
_exceptionHandler(e, s);
291+
} finally {
292+
_clearPhase();
292293
try {
293-
_beginPhase('\$apply');
294-
returnValue = $eval(expr);
294+
$root.$digest();
295295
} catch (e, s) {
296296
_exceptionHandler(e, s);
297-
} finally {
298-
_clearPhase();
299-
try {
300-
$root.$digest();
301-
} catch (e, s) {
302-
_exceptionHandler(e, s);
303-
throw e;
304-
}
305-
}
306-
}, onRunAsync: (fn) {
307-
async.runAsync(() {
308-
// exceptions from fn() can not be caught here, but
309-
// are handled by onError.
310-
executingAsyncCallback = true;
311-
fn();
312-
executingAsyncCallback = false;
313-
try {
314-
$root.$digest();
315-
} catch (e, s) {
316-
_exceptionHandler(e, s);
317-
}
318-
});
319-
},
320-
onError: (e) {
321-
if (executingAsyncCallback) {
322-
// NOTE(deboer): Thrown strings don't have an attached stack trace
323-
// http://dartbug.com/12000
324-
_exceptionHandler(e, async.getAttachedStackTrace(e));
297+
throw e;
325298
}
326-
if (toThrow == null)
327-
toThrow = e;
328-
});
329-
// This will only throw exceptions from the runZoned body.
330-
// The async code will be executed after this check.
331-
if (toThrow != null) {
332-
throw toThrow;
333299
}
334-
return returnValue;
335300
}
336301

337302

test/compiler_spec.dart

+8-16
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,8 @@ main() {
232232
$rootScope.sep = '-';
233233
var element = $(r'<div>{{name}}{{sep}}{{$id}}:<simple>{{name}}{{sep}}{{$id}}</simple></div>');
234234
BlockFactory blockFactory = $compile(element);
235-
$rootScope.$apply(() {
236-
Block block = blockFactory(injector, element);
237-
});
235+
Block block = blockFactory(injector, element);
236+
$rootScope.$digest();
238237

239238
nextTurn();
240239
expect(element.textWithShadow()).toEqual('OUTTER-_1:INNER_2(OUTTER-_1)');
@@ -245,19 +244,15 @@ main() {
245244
$rootScope.val = "poof";
246245
var element = $('<parent-expression from-parent=val></parent-expression>');
247246

248-
$rootScope.$apply(() {
249-
$compile(element)(injector, element);
250-
});
247+
$compile(element)(injector, element);
251248

252249
nextTurn();
253250
expect(renderedText(element)).toEqual('inside poof');
254251
})));
255252

256253
it('should behave nicely if a mapped attribute is missing', async(inject(() {
257254
var element = $('<parent-expression></parent-expression>');
258-
$rootScope.$apply(() {
259-
$compile(element)(injector, element);
260-
});
255+
$compile(element)(injector, element);
261256

262257
nextTurn();
263258
expect(renderedText(element)).toEqual('inside ');
@@ -266,9 +261,7 @@ main() {
266261
it('should behave nicely if a mapped attribute evals to null', async(inject(() {
267262
$rootScope.val = null;
268263
var element = $('<parent-expression fromParent=val></parent-expression>');
269-
$rootScope.$apply(() {
270-
$compile(element)(injector, element);
271-
});
264+
$compile(element)(injector, element);
272265

273266
nextTurn();
274267
expect(renderedText(element)).toEqual('inside ');
@@ -318,11 +311,10 @@ main() {
318311
}).toThrow('No provider found for LocalAttrDirective! (resolving LocalAttrDirective)');
319312
}));
320313

321-
it('should publish component controller into the scope', async(inject((Scope $rootScope) {
314+
it('should publish component controller into the scope', async(inject(() {
322315
var element = $(r'<div><publish-me></publish-me></div>');
323-
$rootScope.$apply(() {
324-
$compile(element)(injector, element);
325-
});
316+
$compile(element)(injector, element);
317+
$rootScope.$apply();
326318

327319
nextTurn();
328320
expect(element.textWithShadow()).toEqual('WORKED');

test/scope_spec.dart

-90
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import "_specs.dart";
2-
import "dart:async";
32

43
main() {
54
describe(r'Scope', () {
@@ -483,95 +482,6 @@ main() {
483482
});
484483
});
485484

486-
describe(r'async', () {
487-
beforeEach(module((AngularModule module) {
488-
return module.type(ExceptionHandler, LogExceptionHandler);
489-
}));
490-
491-
492-
it(r'should run watch cycle on future resolution', async(inject((Scope scope) {
493-
var log = '';
494-
scope['r'] = 0;
495-
scope['qq'] = 0;
496-
scope.$watch('q', (_) {
497-
log += 'q';
498-
scope['qq'] = 1;
499-
new Future.value('b').then((v) {
500-
log += 'b';
501-
scope['r'] = 3;
502-
});
503-
});
504-
505-
scope.$watch('r', (rVal) {
506-
log += 'r';
507-
scope['s'] = rVal * 2;
508-
});
509-
scope.$apply("q=2");
510-
expect(scope['qq']).toEqual(1);
511-
expect(scope['q']).toEqual(2);
512-
expect(scope['r']).toEqual(0);
513-
expect(log).toEqual('qr');
514-
nextTurn(true);
515-
516-
expect(scope['r']).toEqual(3);
517-
expect(scope['s']).toEqual(6);
518-
expect(log).toEqual('qrbr');
519-
})));
520-
521-
522-
it(r'should catch exceptions from futures', async(inject((Scope scope, ExceptionHandler $exceptionHandler) {
523-
scope.$watch('q', (_) {
524-
scope['qq'] = 1;
525-
new Future.value('b').then((v) {
526-
throw "sadface";
527-
});
528-
});
529-
scope.$apply("q=2");
530-
nextTurn(true);
531-
expect($exceptionHandler.errors.length).toEqual(1);
532-
expect($exceptionHandler.errors[0].error).toEqual("sadface");
533-
})));
534-
535-
536-
it(r'should catch exceptions from digests trigger by futures', async(inject((Scope scope, ExceptionHandler $exceptionHandler) {
537-
scope.$watch('q', (_) {
538-
scope['qq'] = 1;
539-
new Future.value('b').then((v) {
540-
scope['x'] = 2;
541-
});
542-
});
543-
scope.$watch('x', (xVal) {
544-
if (xVal == 2) throw "x was 2";
545-
});
546-
scope.$apply("q=2");
547-
nextTurn(true);
548-
expect($exceptionHandler.errors.length).toEqual(1);
549-
expect($exceptionHandler.errors[0].error).toEqual("x was 2");
550-
})));
551-
552-
553-
it(r'should throw from the synchronous code', () {
554-
module((AngularModule module) {
555-
return module.type(ExceptionHandler, ExceptionHandler);
556-
});
557-
558-
async(inject((Scope scope, ExceptionHandler $exceptionHandler) {
559-
scope.$watch('q', (_) {
560-
scope['qq'] = 1;
561-
new Future.value('b').then((v) {
562-
scope['x'] = 2;
563-
});
564-
throw "sync throw";
565-
});
566-
expect(() {
567-
scope.$apply("q=2");
568-
nextTurn(true);
569-
}).toThrow('sync throw');
570-
571-
}));
572-
});
573-
});
574-
575485

576486
describe(r'exceptions', () {
577487
var log;

0 commit comments

Comments
 (0)