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

Commit c9bf23a

Browse files
committed
fix(scope): improve error msg on unstable model
1 parent 84762b1 commit c9bf23a

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

lib/change_detection/watch_group.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ part 'ast.dart';
88
part 'prototype_map.dart';
99

1010
typedef ReactionFn(value, previousValue);
11-
typedef ChangeLog(expression);
11+
typedef ChangeLog(String expression, current, previous);
1212

1313
/**
1414
* Extend this class if you wish to pretend to be a function, but you don't know
@@ -341,7 +341,9 @@ class RootWatchGroup extends WatchGroup {
341341
(_changeDetector as ChangeDetector<_Handler>)
342342
.collectChanges(exceptionHandler);
343343
while (changeRecord != null) {
344-
if (changeLog != null) changeLog(changeRecord.handler.expression);
344+
if (changeLog != null) changeLog(changeRecord.handler.expression,
345+
changeRecord.currentValue,
346+
changeRecord.previousValue);
345347
changeRecord.handler.onChange(changeRecord);
346348
changeRecord = changeRecord.nextChange;
347349
}
@@ -353,7 +355,9 @@ class RootWatchGroup extends WatchGroup {
353355
try {
354356
var change = evalRecord.check();
355357
if (change != null && changeLog != null) {
356-
changeLog(evalRecord.handler.expression);
358+
changeLog(evalRecord.handler.expression,
359+
evalRecord.currentValue,
360+
evalRecord.previousValue);
357361
}
358362
} catch (e, s) {
359363
if (exceptionHandler == null) rethrow; else exceptionHandler(e, s);

lib/core/scope.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class RootScope extends Scope {
352352
if (changeLog == null) {
353353
log = [];
354354
digestLog = [];
355-
changeLog = (value) => digestLog.add(value);
355+
changeLog = (e, c, p) => digestLog.add('$e: $c <= $p');
356356
} else {
357357
log.add(digestLog.join(', '));
358358
digestLog.clear();
@@ -398,8 +398,10 @@ class RootScope extends Scope {
398398
assert((() {
399399
var watchLog = [];
400400
var observeLog = [];
401-
(watchGroup as RootWatchGroup).detectChanges(changeLog: watchLog.add);
402-
(observeGroup as RootWatchGroup).detectChanges(changeLog: observeLog.add);
401+
(watchGroup as RootWatchGroup).detectChanges(
402+
changeLog: (s, c, p) => watchLog.add('$s: $c <= $p'));
403+
(observeGroup as RootWatchGroup).detectChanges(
404+
changeLog: (s, c, p) => watchLog.add('$s: $c <= $p'));
403405
if (watchLog.isNotEmpty || observeLog.isNotEmpty) {
404406
throw 'Observer reaction functions should not change model. \n'
405407
'These watch changes were detected: ${watchLog.join('; ')}\n'

lib/core_dom/ng_mustache.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NgTextMustacheDirective {
1919
List items = interpolation.expressions.map((exp) {
2020
return parser(exp, filters:filters);
2121
}).toList();
22-
AST ast = new PureFunctionAST(markup, new ArrayFn(), items);
22+
AST ast = new PureFunctionAST('[[$markup]]', new ArrayFn(), items);
2323
scope.observe(ast, interpolation.call);
2424
}
2525

@@ -51,7 +51,7 @@ class NgAttrMustacheDirective {
5151
List items = interpolation.expressions.map((exp) {
5252
return parser(exp, filters:filters);
5353
}).toList();
54-
AST ast = new PureFunctionAST(markup, new ArrayFn(), items);
54+
AST ast = new PureFunctionAST('[[$markup]]', new ArrayFn(), items);
5555
/*
5656
Attribute bindings are tricky. They need to be resolved on digest
5757
inline with components so that any bindings to component can

test/core/scope_spec.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ main() => describe('scope', () {
708708
retValue = 2;
709709
expect(rootScope.flush).
710710
toThrow('Observer reaction functions should not change model. \n'
711-
'These watch changes were detected: logger("watch")\n'
711+
'These watch changes were detected: logger("watch"): 2 <= 1\n'
712712
'These observe changes were detected: ');
713713
}));
714714
});
@@ -949,9 +949,9 @@ main() => describe('scope', () {
949949
rootScope.digest();
950950
}).toThrow('Model did not stabilize in 5 digests. '
951951
'Last 3 iterations:\n'
952-
'a, b\n'
953-
'a, b\n'
954-
'a, b');
952+
'a: 2 <= 1, b: 2 <= 1\n'
953+
'a: 3 <= 2, b: 3 <= 2\n'
954+
'a: 4 <= 3, b: 4 <= 3');
955955
}));
956956

957957

0 commit comments

Comments
 (0)