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

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

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