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

Commit

Permalink
Revert "feat(Scope): Instrument Scope to use User tags in Dart Oberva…
Browse files Browse the repository at this point in the history
…tory"

This is only reverted because it is not ready for g3v1x.
We will re-apply this when we have the 'ok' to merge it into g3v1x.

This reverts commit c21ac7e.

Conflicts:
	lib/core/scope.dart
  • Loading branch information
jbdeboer committed Jul 1, 2014
1 parent caf4275 commit 6161600
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 86 deletions.
37 changes: 6 additions & 31 deletions lib/change_detection/watch_group.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library angular.watch_group;

import 'dart:profiler';
import 'package:angular/change_detection/change_detection.dart';
import 'dart:collection';

Expand Down Expand Up @@ -368,8 +367,6 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
class RootWatchGroup extends WatchGroup {
final FieldGetterFactory _fieldGetterFactory;
Watch _dirtyWatchHead, _dirtyWatchTail;
List<UserTag> _detectChangesTags = [];
List<UserTag> _reactionFnTags = [];

/**
* Every time a [WatchGroup] is destroyed we increment the counter. During
Expand All @@ -381,22 +378,10 @@ class RootWatchGroup extends WatchGroup {
int _removeCount = 0;


RootWatchGroup(this._fieldGetterFactory, ChangeDetector changeDetector, Object context, {
bool profile: false, int ttl })
: super._root(changeDetector, context) {
if (profile) {
_detectChangesTags = new List(ttl + 2);
_reactionFnTags = new List(ttl + 2);
for (int i = 0; i < ttl; i++) {
_detectChangesTags[i] = new UserTag('DetectChanges / NgDigest${i}');
_reactionFnTags[i] = new UserTag('ReactionFn / NgDigest${i}');
}
_detectChangesTags[ttl] = new UserTag('DetectChanges / NgFlush');
_detectChangesTags[ttl + 1] = new UserTag('DetectChanges / NgAssert');
_reactionFnTags[ttl] = new UserTag('ReactionFn / NgFlush');
_reactionFnTags[ttl + 1] = new UserTag('ReactionFn / NgAssert');
}
}
RootWatchGroup(this._fieldGetterFactory,
ChangeDetector changeDetector,
Object context)
: super._root(changeDetector, context);

RootWatchGroup get _rootGroup => this;

Expand All @@ -415,10 +400,7 @@ class RootWatchGroup extends WatchGroup {
ChangeLog changeLog,
AvgStopwatch fieldStopwatch,
AvgStopwatch evalStopwatch,
AvgStopwatch processStopwatch,
num sequenceNumber}) {
var previous;
if (sequenceNumber != null) previous = _detectChangesTags[sequenceNumber].makeCurrent();
AvgStopwatch processStopwatch}) {
// Process the Records from the change detector
Iterator<Record<_Handler>> changedRecordIterator =
(_changeDetector as ChangeDetector<_Handler>).collectChanges(
Expand Down Expand Up @@ -466,13 +448,7 @@ class RootWatchGroup extends WatchGroup {
count++;
try {
if (root._removeCount == 0 || dirtyWatch._watchGroup.isAttached) {
if (sequenceNumber != null) {
var previous = _reactionFnTags[sequenceNumber].makeCurrent();
dirtyWatch.invoke();
previous.makeCurrent();
} else {
dirtyWatch.invoke();
}
dirtyWatch.invoke();
}
} catch (e, s) {
if (exceptionHandler == null) rethrow; else exceptionHandler(e, s);
Expand All @@ -486,7 +462,6 @@ class RootWatchGroup extends WatchGroup {
root._removeCount = 0;
}
if (processStopwatch != null) processStopwatch..stop()..increment(count);
if (previous != null) previous.makeCurrent();
return count;
}

Expand Down
1 change: 0 additions & 1 deletion lib/core/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library angular.core_internal;
import 'dart:async' as async;
import 'dart:collection';
import 'dart:math';
import 'dart:profiler';
import 'package:intl/intl.dart';

import 'package:di/di.dart';
Expand Down
61 changes: 12 additions & 49 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ part of angular.core_internal;
typedef EvalFunction0();
typedef EvalFunction1(context);

final UserTag APPLY_USER_TAG = new UserTag('Apply');
final UserTag FLUSH_TAG = new UserTag('NgFlush');
final UserTag RUN_ASYNC_TAG = new UserTag('NgRunAsync');
final UserTag DOM_READ_TAG = new UserTag('NgDomRead');
final UserTag DOM_WRITE_TAG = new UserTag('NgDomWrite');
final UserTag ASSERT_TAG = new UserTag('NgAssert');

/**
* Injected into the listener function within [Scope.on] to provide
* event-specific details to the scope listener.
Expand Down Expand Up @@ -295,15 +288,13 @@ class Scope {
}

dynamic apply([expression, Map locals]) {
var previous = APPLY_USER_TAG.makeCurrent();
_assertInternalStateConsistency();
rootScope._transitionState(null, RootScope.STATE_APPLY);
try {
return eval(expression, locals);
} catch (e, s) {
rootScope._exceptionHandler(e, s);
} finally {
previous.makeCurrent();
rootScope.._transitionState(RootScope.STATE_APPLY, null)
..digest()
..flush();
Expand Down Expand Up @@ -585,8 +576,6 @@ class RootScope extends Scope {

String _state;

final List<UserTag> _digestTags = [];

/**
*
* While processing data bindings, Angular passes through multiple states. When testing or
Expand Down Expand Up @@ -636,30 +625,24 @@ class RootScope extends Scope {
*/
String get state => _state;

RootScope(Object context, Parser parser, ASTParser astParser,
FieldGetterFactory fieldGetterFactory, FormatterMap formatters, this._exceptionHandler,
ScopeDigestTTL ttl, this._zone, ScopeStats _scopeStats, CacheRegister cacheRegister)
RootScope(Object context, Parser parser, ASTParser astParser, FieldGetterFactory fieldGetterFactory,
FormatterMap formatters, this._exceptionHandler, this._ttl, this._zone,
ScopeStats _scopeStats, CacheRegister cacheRegister)
: _scopeStats = _scopeStats,
_ttl = ttl,
_parser = parser,
_astParser = astParser,
super(context, null, null,
new RootWatchGroup(fieldGetterFactory,
new DirtyCheckingChangeDetector(fieldGetterFactory), context, profile: true,
ttl: ttl.ttl),
new DirtyCheckingChangeDetector(fieldGetterFactory), context),
new RootWatchGroup(fieldGetterFactory,
new DirtyCheckingChangeDetector(fieldGetterFactory), context, profile: true,
ttl: ttl.ttl),
new DirtyCheckingChangeDetector(fieldGetterFactory), context),
'',
_scopeStats)
{
_zone.onTurnDone = apply;
_zone.onError = (e, s, ls) => _exceptionHandler(e, s);
_zone.onScheduleMicrotask = runAsync;
for(num i = 0; i <= _ttl.ttl; i++) {
_digestTags.add(new UserTag('NgDigest${i}'));
}
cacheRegister.registerCache("ScopeWatchASTs", astCache);
cacheRegister.registerCache("ScopeWatchASTs", astCache);
}

RootScope get rootScope => this;
Expand All @@ -683,21 +666,18 @@ class RootScope extends Scope {
* [ScopeDigestTTL].
*/
void digest() {
int digestTTL = _ttl.ttl;
_transitionState(null, STATE_DIGEST);
try {
var rootWatchGroup = _readWriteGroup as RootWatchGroup;


int digestTTL = _ttl.ttl;
const int LOG_COUNT = 3;
List log;
List digestLog;
var count;
ChangeLog changeLog;
_scopeStats.digestStart();
do {
var sequenceNo = _ttl.ttl - digestTTL;
var previousTag = _digestTags[sequenceNo].makeCurrent();

int asyncCount = _runAsyncFns();

Expand All @@ -707,8 +687,7 @@ class RootScope extends Scope {
changeLog: changeLog,
fieldStopwatch: _scopeStats.fieldStopwatch,
evalStopwatch: _scopeStats.evalStopwatch,
processStopwatch: _scopeStats.processStopwatch,
sequenceNumber: sequenceNo);
processStopwatch: _scopeStats.processStopwatch);

if (digestTTL <= LOG_COUNT) {
if (changeLog == null) {
Expand All @@ -721,13 +700,10 @@ class RootScope extends Scope {
}
}
if (digestTTL == 0) {
if (previousTag != null) previousTag.makeCurrent();
throw 'Model did not stabilize in ${_ttl.ttl} digests. '
'Last $LOG_COUNT iterations:\n${log.join('\n')}';
'Last $LOG_COUNT iterations:\n${log.join('\n')}';
}

_scopeStats.digestLoop(count);
previousTag.makeCurrent();
} while (count > 0 || _runAsyncHead != null);
} finally {
_scopeStats.digestEnd();
Expand All @@ -736,7 +712,6 @@ class RootScope extends Scope {
}

void flush() {
var previousTag = FLUSH_TAG.makeCurrent();
_stats.flushStart();
_transitionState(null, STATE_FLUSH);
RootWatchGroup readOnlyGroup = this._readOnlyGroup as RootWatchGroup;
Expand All @@ -759,8 +734,7 @@ class RootScope extends Scope {
readOnlyGroup.detectChanges(exceptionHandler:_exceptionHandler,
fieldStopwatch: _scopeStats.fieldStopwatch,
evalStopwatch: _scopeStats.evalStopwatch,
processStopwatch: _scopeStats.processStopwatch,
sequenceNumber: _ttl.ttl);
processStopwatch: _scopeStats.processStopwatch);
}
if (_domReadHead != null) _stats.domReadStart();
while (_domReadHead != null) {
Expand All @@ -777,35 +751,30 @@ class RootScope extends Scope {
} while (_domWriteHead != null || _domReadHead != null || _runAsyncHead != null);
_stats.flushEnd();
assert((() {
var previousTag = ASSERT_TAG.makeCurrent();
_stats.flushAssertStart();
var digestLog = [];
var flushLog = [];
(_readWriteGroup as RootWatchGroup).detectChanges(
changeLog: (s, c, p) => digestLog.add('$s: $c <= $p'),
fieldStopwatch: _scopeStats.fieldStopwatch,
evalStopwatch: _scopeStats.evalStopwatch,
processStopwatch: _scopeStats.processStopwatch,
sequenceNumber: _ttl.ttl + 1);
processStopwatch: _scopeStats.processStopwatch);
(_readOnlyGroup as RootWatchGroup).detectChanges(
changeLog: (s, c, p) => flushLog.add('$s: $c <= $p'),
fieldStopwatch: _scopeStats.fieldStopwatch,
evalStopwatch: _scopeStats.evalStopwatch,
processStopwatch: _scopeStats.processStopwatch,
sequenceNumber: _ttl.ttl + 1);
processStopwatch: _scopeStats.processStopwatch);
if (digestLog.isNotEmpty || flushLog.isNotEmpty) {
throw 'Observer reaction functions should not change model. \n'
'These watch changes were detected: ${digestLog.join('; ')}\n'
'These observe changes were detected: ${flushLog.join('; ')}';
}
_stats.flushAssertEnd();
previousTag.makeCurrent();
return true;
})());
} finally {
_stats.cycleEnd();
_transitionState(STATE_FLUSH, null);
previousTag.makeCurrent();
}
}

Expand All @@ -814,14 +783,12 @@ class RootScope extends Scope {
if (_state == STATE_FLUSH_ASSERT) {
throw "Scheduling microtasks not allowed in $state state.";
}
var previousTag = RUN_ASYNC_TAG.makeCurrent();
var chain = new _FunctionChain(fn);
if (_runAsyncHead == null) {
_runAsyncHead = _runAsyncTail = chain;
} else {
_runAsyncTail = _runAsyncTail._next = chain;
}
previousTag.makeCurrent();
}

_runAsyncFns() {
Expand All @@ -840,25 +807,21 @@ class RootScope extends Scope {
}

void domWrite(fn()) {
var previousTag = DOM_WRITE_TAG.makeCurrent();
var chain = new _FunctionChain(fn);
if (_domWriteHead == null) {
_domWriteHead = _domWriteTail = chain;
} else {
_domWriteTail = _domWriteTail._next = chain;
}
previousTag.makeCurrent();
}

void domRead(fn()) {
var previousTag = DOM_READ_TAG.makeCurrent();
var chain = new _FunctionChain(fn);
if (_domReadHead == null) {
_domReadHead = _domReadTail = chain;
} else {
_domReadTail = _domReadTail._next = chain;
}
previousTag.makeCurrent();
}

void destroy() {}
Expand Down
1 change: 0 additions & 1 deletion lib/core_dom/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:async' as async;
import 'dart:convert' show JSON;
import 'dart:html' as dom;
import 'dart:js' as js;
import 'dart:profiler';

import 'package:di/di.dart';
import 'package:perf_api/perf_api.dart';
Expand Down
4 changes: 0 additions & 4 deletions lib/core_dom/tagging_view_factory.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
part of angular.core.dom_internal;

var ngViewTag = new UserTag('NgView');

class TaggingViewFactory implements ViewFactory {
final List<TaggedElementBinder> elementBinders;
final List<dom.Node> templateNodes;
Expand All @@ -14,7 +12,6 @@ class TaggingViewFactory implements ViewFactory {
static Key _EVENT_HANDLER_KEY = new Key(EventHandler);

View call(Injector injector, [List<dom.Node> nodes /* TODO: document fragment */]) {
var lastTag = ngViewTag.makeCurrent();
if (nodes == null) {
nodes = cloneElements(templateNodes);
}
Expand All @@ -25,7 +22,6 @@ class TaggingViewFactory implements ViewFactory {
_link(view, nodes, injector);
return view;
} finally {
lastTag.makeCurrent();
assert(_perf.stopTimer(timerId) != false);
}
}
Expand Down

0 comments on commit 6161600

Please sign in to comment.