Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: sky/framework/node.dart

Issue 1132063007: Rationalize Dart mojo and sky package structure (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/net/fetch.dart ('k') | sky/framework/reflect.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 library node;
2
3 class Node {
4
5 // Nodes always have a 'depth' greater than their ancestors'.
6 // There's no guarantee regarding depth between siblings. The depth
7 // of a node is used to ensure that nodes are processed in depth
8 // order. The 'depth' of a child can be more than one greater than
9 // the 'depth' of the parent, because the 'depth' values are never
10 // decreased: all that matters is that it's greater than the parent.
11 // Consider a tree with a root node A, a child B, and a grandchild
12 // C. Initially, A will have 'depth' 0, B 'depth' 1, and C 'depth'
13 // 2. If C is moved to be a child of A, sibling of B, then the
14 // numbers won't change. C's 'depth' will still be 2.
15
16 int _depth = 0;
17 int get depth => _depth;
18 void redepthChild(Node child) { // internal, do not call
19 assert(child._attached == _attached);
20 if (child._depth <= _depth) {
21 child._depth = _depth + 1;
22 child.redepthChildren();
23 }
24 }
25 void redepthChildren() { // internal, do not call
26 // override this in subclasses with child nodes
27 // simply call redepthChild(child) for each child
28 }
29
30 bool _attached = false;
31 bool get attached => _attached;
32 void attach() {
33 // override this in subclasses with child nodes
34 // simply call attach() for each child then call your superclass
35 _attached = true;
36 attachChildren();
37 }
38 attachChildren() { } // workaround for lack of inter-class mixins in Dart
39 void detach() {
40 // override this in subclasses with child nodes
41 // simply call detach() for each child then call your superclass
42 _attached = false;
43 detachChildren();
44 }
45 detachChildren() { } // workaround for lack of inter-class mixins in Dart
46
47 void setAsChild(Node child) { // only for use by subclasses
48 assert(child != null);
49 if (attached)
50 child.attach();
51 redepthChild(child);
52 }
53 void dropChild(Node child) { // only for use by subclasses
54 assert(child != null);
55 assert(child.attached == attached);
56 if (attached)
57 child.detach();
58 }
59
60 }
OLDNEW
« no previous file with comments | « sky/framework/net/fetch.dart ('k') | sky/framework/reflect.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698