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

Commit 8f865e5

Browse files
committed
docs(Scope): adding documentation
1 parent 8d0f8d9 commit 8f865e5

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

lib/core/scope.dart

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ typedef EvalFunction1(context);
1414
class ScopeEvent {
1515
static final String DESTROY = 'ng-destroy';
1616

17+
/**
18+
* Data attached to the event. This would be the optional parameter
19+
* from [Scope.emit] and [Scope.broadcast].
20+
*/
1721
final data;
1822

1923
/**
@@ -27,7 +31,10 @@ class ScopeEvent {
2731
final Scope targetScope;
2832

2933
/**
30-
* The destination scope that intercepted the event.
34+
* The destination scope that intercepted the event. As
35+
* the event traverses the scope hierarchy the the event instance
36+
* stays the same, but the [currentScope] reflects the scope
37+
* of the current listener which is firing.
3138
*/
3239
Scope get currentScope => _currentScope;
3340
Scope _currentScope;
@@ -118,12 +125,35 @@ class ScopeLocals implements Map {
118125
dynamic putIfAbsent(key, fn) => _scope.putIfAbsent(key, fn);
119126
}
120127

128+
/**
129+
* [Scope] is represents a collection of [watch]es [observe]ers, and [context]
130+
* for the watchers, observers and [eval]uations. Scopes structure loosely
131+
* mimics the DOM structure. Scopes and [Block]s are bound to each other.
132+
* As scopes are created and destroyed by [BlockFactory] they are responsible
133+
* for change detection, change processing and memory management.
134+
*/
121135
class Scope {
136+
137+
/**
138+
* The default execution context for [watch]es [observe]ers, and [eval]uation.
139+
*/
122140
final context;
141+
142+
/**
143+
* The [RootScope] of the application.
144+
*/
123145
final RootScope rootScope;
146+
124147
Scope _parentScope;
148+
149+
/**
150+
* The parent [Scope].
151+
*/
125152
Scope get parentScope => _parentScope;
126153

154+
// TODO(misko): WatchGroup should be private.
155+
// Instead we should expose performance stats about the watches
156+
// such as # of watches, checks/1ms, field checks, function checks, etc
127157
final WatchGroup watchGroup;
128158
final WatchGroup observeGroup;
129159
final int _depth;
@@ -136,6 +166,12 @@ class Scope {
136166
Scope(Object this.context, this.rootScope, this._parentScope, this._depth,
137167
this._index, this.watchGroup, this.observeGroup);
138168

169+
/**
170+
* A [watch] sets up a watch in the [digest] phase of the [apply] cycle.
171+
*
172+
* Use [watch] if the reaction function can cause updates to model. In your
173+
* controller code you will most likely use [watch].
174+
*/
139175
Watch watch(expression, ReactionFn reactionFn, {context, FilterMap filters}) {
140176
assert(expression != null);
141177
AST ast = expression is AST

0 commit comments

Comments
 (0)