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

Side by Side Diff: third_party/pkg/angular/lib/introspection.dart

Issue 180843004: Revert revision 33053 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 part of angular; 1 part of angular;
2 2
3 /** 3 /**
4 * A global write only variable which keeps track of objects attached to the 4 * A global write only variable which keeps track of objects attached to the ele ments.
5 * elements. This is useful for debugging AngularDart application from the 5 * This is usefull for debugging AngularDart application from the browser's REPL .
6 * browser's REPL.
7 */ 6 */
8 var _elementExpando = new Expando('element'); 7 Expando _elementExpando = new Expando('element');
9 8
10 /** 9 /**
11 * Return the closest [ElementProbe] object for a given [Element]. 10 * Return the closest [ElementProbe] object for a given [Element].
12 * 11 *
13 * NOTE: This global method is here to make it easier to debug Angular 12 * NOTE: This global method is here to make it easier to debug Angular applicati on from
14 * application from the browser's REPL, unit or end-to-end tests. The 13 * the browser's REPL, unit or end-to-end tests. The function is not inten ded to
15 * function is not intended to be called from Angular application. 14 * be called from Angular application.
16 */ 15 */
17 ElementProbe ngProbe(dom.Node node) { 16 ElementProbe ngProbe(dom.Node node) {
18 while(node != null) { 17 while(node != null) {
19 var probe = _elementExpando[node]; 18 var probe = _elementExpando[node];
20 if (probe != null) return probe; 19 if (probe != null) return probe;
21 node = node.parent; 20 node = node.parent;
22 } 21 }
23 return null; 22 return null;
24 } 23 }
25 24
26 25
27 /** 26 /**
28 * Return the [Injector] associated with a current [Element]. 27 * Return the [Injector] associated with a current [Element].
29 * 28 *
30 * **NOTE**: This global method is here to make it easier to debug Angular 29 * **NOTE**: This global method is here to make it easier to debug Angular appli cation from
31 * application from the browser's REPL, unit or end-to-end tests. The function 30 * the browser's REPL, unit or end-to-end tests. The function is not intended to be called
32 * is not intended to be called from Angular application. 31 * from Angular application.
33 */ 32 */
34 Injector ngInjector(dom.Node node) => ngProbe(node).injector; 33 Injector ngInjector(dom.Node node) => ngProbe(node).injector;
35 34
36 35
37 /** 36 /**
38 * Return the [Scope] associated with a current [Element]. 37 * Return the [Scope] associated with a current [Element].
39 * 38 *
40 * **NOTE**: This global method is here to make it easier to debug Angular 39 * **NOTE**: This global method is here to make it easier to debug Angular appli cation from
41 * application from the browser's REPL, unit or end-to-end tests. The function 40 * the browser's REPL, unit or end-to-end tests. The function is not intended to be called
42 * is not intended to be called from Angular application. 41 * from Angular application.
43 */ 42 */
44 Scope ngScope(dom.Node node) => ngProbe(node).scope; 43 Scope ngScope(dom.Node node) => ngProbe(node).scope;
45 44
46 45
47 List<dom.Element> ngQuery(dom.Node element, String selector, 46 List<dom.Element> ngQuery(dom.Node element, String selector, [String containsTex t]) {
48 [String containsText]) {
49 var list = []; 47 var list = [];
50 var children = [element]; 48 var children = [element];
51 if ((element is dom.Element) && element.shadowRoot != null) { 49 if ((element is dom.Element) && element.shadowRoot != null) {
52 children.add(element.shadowRoot); 50 children.add(element.shadowRoot);
53 } 51 }
54 while (!children.isEmpty) { 52 while (!children.isEmpty) {
55 var child = children.removeAt(0); 53 var child = children.removeAt(0);
56 child.querySelectorAll(selector).forEach((e) { 54 child.querySelectorAll(selector).forEach((e) {
57 if (containsText == null || e.text.contains(containsText)) list.add(e); 55 if (containsText == null || e.text.contains(containsText)) list.add(e);
58 }); 56 });
59 child.querySelectorAll('*').forEach((e) { 57 child.querySelectorAll('*').forEach((e) {
60 if (e.shadowRoot != null) children.add(e.shadowRoot); 58 if (e.shadowRoot != null) children.add(e.shadowRoot);
61 }); 59 });
62 } 60 }
63 return list; 61 return list;
64 } 62 }
65 63
66 /** 64 /**
67 * Return a List of directive controllers associated with a current [Element]. 65 * Return a List of directive controllers associated with a current [Element].
68 * 66 *
69 * **NOTE**: This global method is here to make it easier to debug Angular 67 * **NOTE**: This global method is here to make it easier to debug Angular appli cation from
70 * application from the browser's REPL, unit or end-to-end tests. The function 68 * the browser's REPL, unit or end-to-end tests. The function is not intended to be called
71 * is not intended to be called from Angular application. 69 * from Angular application.
72 */ 70 */
73 List<Object> ngDirectives(dom.Node node) { 71 List<Object> ngDirectives(dom.Node node) {
74 ElementProbe probe = _elementExpando[node]; 72 ElementProbe probe = _elementExpando[node];
75 return probe == null ? [] : probe.directives; 73 return probe == null ? [] : probe.directives;
76 } 74 }
77 75
78 _publishToJavaScript() { 76 _publishToJavaScript() {
79 js.context 77 js.context['ngProbe'] = (dom.Node node) => _jsProbe(ngProbe(node));
80 ..['ngProbe'] = (dom.Node node) => _jsProbe(ngProbe(node)) 78 js.context['ngInjector'] = (dom.Node node) => _jsInjector(ngInjector(node));
81 ..['ngInjector'] = (dom.Node node) => _jsInjector(ngInjector(node)) 79 js.context['ngScope'] = (dom.Node node) => _jsScope(ngScope(node));
82 ..['ngScope'] = (dom.Node node) => _jsScope(ngScope(node)) 80 js.context['ngQuery'] = (dom.Node node, String selector, [String containsText] ) =>
83 ..['ngQuery'] = (dom.Node node, String selector, [String containsText]) => 81 new js.JsArray.from(ngQuery(node, selector, containsText));
84 new js.JsArray.from(ngQuery(node, selector, containsText));
85 } 82 }
86 83
87 js.JsObject _jsProbe(ElementProbe probe) { 84 js.JsObject _jsProbe(ElementProbe probe) {
88 return new js.JsObject.jsify({ 85 return new js.JsObject.jsify({
89 "element": probe.element, 86 "element": probe.element,
90 "injector": _jsInjector(probe.injector), 87 "injector": _jsInjector(probe.injector),
91 "scope": _jsScope(probe.scope), 88 "scope": _jsScope(probe.scope),
92 "directives": probe.directives.map((directive) => _jsDirective(directive)) 89 "directives": probe.directives.map((directive) => _jsDirective(directive))
93 })..['_dart_'] = probe; 90 })..['_dart_'] = probe;
94 } 91 }
95 92
96 js.JsObject _jsInjector(Injector injector) => 93 js.JsObject _jsInjector(Injector injector) {
97 new js.JsObject.jsify({"get": injector.get})..['_dart_'] = injector; 94 return new js.JsObject.jsify({
95 "get": injector.get
96 })..['_dart_'] = injector;
97 }
98 98
99 js.JsObject _jsScope(Scope scope) { 99 js.JsObject _jsScope(Scope scope) {
100 return new js.JsObject.jsify({ 100 return new js.JsObject.jsify({
101 "apply": scope.apply, 101 "\$apply": scope.$apply,
102 "digest": scope.rootScope.digest, 102 "\$digest": scope.$digest,
103 "flush": scope.rootScope.flush, 103 "get": (name) => scope[name],
104 "context": scope.context, 104 "set": (name, value) => scope[name] = value
105 "get": (name) => scope.context[name],
106 "set": (name, value) => scope.context[name] = value
107 })..['_dart_'] = scope; 105 })..['_dart_'] = scope;
108 } 106 }
109 107
110 _jsDirective(directive) => directive; 108 _jsDirective(directive) => directive;
OLDNEW
« no previous file with comments | « third_party/pkg/angular/lib/filter/number.dart ('k') | third_party/pkg/angular/lib/mock/debug.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698