Skip to content

Remove usage of (deprecated) probe #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions lib/introspection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,27 @@ List<ElementProbe> _findAllProbesInTree(dom.Node node) {
*
* The node parameter could be:
* * a [dom.Node],
* * a CSS selector for this node.
* * a CSS selector to look for a matching node inside the [root] or the dom.document.
*
* **NOTE:** This global method is here to make it easier to debug Angular
* application from the browser's REPL, unit or end-to-end tests. The
* function is not intended to be called from Angular application.
*/
ElementProbe ngProbe(nodeOrSelector) {
if (nodeOrSelector == null) throw "ngProbe called without node";
ElementProbe ngProbe(nodeOrSelector, [dom.Node root]) {
if (nodeOrSelector == null) throw "ngProbe called without node/selector";
var node = nodeOrSelector;
if (nodeOrSelector is String) {
var nodes = ngQuery(dom.document, nodeOrSelector);
node = (nodes.isNotEmpty) ? nodes.first : null;
if (root == null) {
root = dom.document;
} else {
root = new dom.DivElement()..append(root);
}
var nodes = ngQuery(root, nodeOrSelector);
if (nodes.isEmpty) throw "The '$nodeOrSelector' selector does not match any node";
node = nodes.first;
}
var probe = _findProbeWalkingUp(node);
if (probe != null) {
return probe;
}
if (probe != null) return probe;
var forWhat = (nodeOrSelector is String) ? "selector" : "node";
throw "Could not find a probe for the $forWhat '$nodeOrSelector' nor its parents";
}
Expand All @@ -93,7 +97,8 @@ ElementProbe ngProbe(nodeOrSelector) {
* application from the browser's REPL, unit or end-to-end tests. The function
* is not intended to be called from Angular application.
*/
DirectiveInjector ngInjector(nodeOrSelector) => ngProbe(nodeOrSelector).injector;
DirectiveInjector ngInjector(nodeOrSelector, [dom.Node root]) =>
ngProbe(nodeOrSelector, root).injector;


/**
Expand All @@ -103,17 +108,16 @@ DirectiveInjector ngInjector(nodeOrSelector) => ngProbe(nodeOrSelector).injector
* application from the browser's REPL, unit or end-to-end tests. The function
* is not intended to be called from Angular application.
*/
Scope ngScope(nodeOrSelector) => ngProbe(nodeOrSelector).scope;
Scope ngScope(nodeOrSelector, [dom.Node root]) => ngProbe(nodeOrSelector, root).scope;


List<dom.Element> ngQuery(dom.Node element, String selector,
[String containsText]) {
List<dom.Element> ngQuery(dom.Node element, String selector, [String containsText]) {
var list = [];
var children = [element];
if ((element is dom.Element) && element.shadowRoot != null) {
children.add(element.shadowRoot);
}
while (!children.isEmpty) {
while (children.isNotEmpty) {
var child = children.removeAt(0);
child.querySelectorAll(selector).forEach((e) {
if (containsText == null || e.text.contains(containsText)) list.add(e);
Expand All @@ -136,7 +140,6 @@ List<dom.Element> ngQuery(dom.Node element, String selector,
List<Object> ngDirectives(nodeOrSelector) => ngProbe(nodeOrSelector).directives;



js.JsObject _jsProbe(ElementProbe probe) {
return _jsify({
"element": probe.element,
Expand Down Expand Up @@ -217,7 +220,7 @@ _jsify(var obj) {
return _jsFunction(obj);
}
if ((obj is Map) || (obj is Iterable)) {
var mappedObj = (obj is Map) ?
var mappedObj = (obj is Map) ?
new Map.fromIterables(obj.keys, obj.values.map(_jsify)) : obj.map(_jsify);
if (obj is List) {
return new js.JsArray.from(mappedObj);
Expand Down
2 changes: 1 addition & 1 deletion lib/mock/test_bed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TestBed {
} else {
throw 'Expecting: String, Node, or List<Node> got $html.';
}
rootElement = rootElements.length > 0 && rootElements[0] is Element ? rootElements[0] : null;
rootElement = rootElements.isNotEmpty && rootElements[0] is Element ? rootElements[0] : null;
if (directives == null) {
directives = injector.getByKey(DIRECTIVE_MAP_KEY);
}
Expand Down
20 changes: 13 additions & 7 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import '../_specs.dart';
import 'package:angular/core_dom/directive_injector.dart';


forBothCompilers(fn) {
var probeEnabled;

forCompilerSetups(fn) {
describe('walking compiler', () {
probeEnabled = true;
beforeEachModule((Module m) {
m.bind(Compiler, toImplementation: WalkingCompiler);
return m;
Expand All @@ -14,6 +17,7 @@ forBothCompilers(fn) {
});

describe('tagging compiler', () {
probeEnabled = true;
beforeEachModule((Module m) {
m.bind(Compiler, toImplementation: TaggingCompiler);
return m;
Expand All @@ -22,6 +26,7 @@ forBothCompilers(fn) {
});

describe('tagging compiler with ElementProbe disabled', () {
probeEnabled = false;
beforeEachModule((Module m) {
m.bind(Compiler, toImplementation: TaggingCompiler);
m.bind(CompilerConfig, toValue: new CompilerConfig.withOptions(elementProbeEnabled: false));
Expand All @@ -32,7 +37,9 @@ forBothCompilers(fn) {
}

forAllCompilersAndComponentFactories(fn) {
forBothCompilers(fn);
describe('shadow dom components', () {
forCompilerSetups(fn);
});

describe('transcluding components', () {
beforeEachModule((Module m) {
Expand All @@ -46,7 +53,7 @@ forAllCompilersAndComponentFactories(fn) {
}

void main() {
forBothCompilers((compilerType) =>
forCompilerSetups((compilerType) =>
describe('TranscludingComponentFactory', () {
TestBed _;

Expand Down Expand Up @@ -370,7 +377,7 @@ void main() {
}));

it('should store ElementProbe with Elements', async(() {
if (compilerType == 'tagging-no-elementProbe') return;
if (!probeEnabled) return;

_.compile('<div><simple>innerText</simple></div>');
microLeap();
Expand Down Expand Up @@ -632,9 +639,8 @@ void main() {
});

it('should expose PublishModuleDirectiveSuperType as PublishModuleDirectiveSuperType', () {
_.compile(r'<div publish-types probe="publishModuleProbe"></div>');
Probe probe = _.rootScope.context['publishModuleProbe'];
var directive = probe.injector.get(PublishModuleDirectiveSuperType);
_.compile(r'<div publish-types></div>');
var directive = PublishModuleAttrDirective._injector.get(PublishModuleDirectiveSuperType);
expect(directive is PublishModuleAttrDirective).toBeTruthy();
});

Expand Down
10 changes: 6 additions & 4 deletions test/core_dom/view_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ main() {

Compiler compiler = rootInjector.get(Compiler);
DirectiveMap directives = rootInjector.get(DirectiveMap);
compiler(es('<dir-a>{{\'a\' | formatterA}}</dir-a><dir-b></dir-b>'), directives)(rootScope, rootInjector.get(DirectiveInjector));
var els = es('<dir-a>{{\'a\' | formatterA}}</dir-a><dir-b></dir-b>');
compiler(els, directives)(rootScope, rootInjector.get(DirectiveInjector));
rootScope.apply();

expect(log.log, equals(['AFormatter', 'ADirective']));
Expand All @@ -232,11 +233,12 @@ main() {

DirectiveMap newDirectives = childInjector.get(DirectiveMap);
var scope = childInjector.get(Scope);
compiler(es('<dir-a probe="dirA"></dir-a>{{\'a\' | formatterA}}'
'<dir-b probe="dirB"></dir-b>{{\'b\' | formatterB}}'), newDirectives)(scope, childInjector.get(DirectiveInjector));
els = es('<dir-a></dir-a>{{\'a\' | formatterA}}<dir-b></dir-b>{{\'b\' | formatterB}}');
compiler(els, newDirectives)(scope, childInjector.get(DirectiveInjector));
rootScope.apply();

expect(log.log, equals(['AFormatter', 'ADirective', 'BFormatter', 'ADirective', 'BDirective']));
expect(log.log)
.toEqual(['AFormatter', 'ADirective', 'BFormatter', 'ADirective', 'BDirective']);
});

});
Expand Down
Loading