Skip to content

Commit 918226b

Browse files
committed
chore(jquery): Remove the JQuery class from AngularDart
Closes dart-archive#219
1 parent e75e3b4 commit 918226b

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

test/_specs.dart

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export 'package:perf_api/perf_api.dart';
2020
es(String html) {
2121
var div = new DivElement();
2222
div.setInnerHtml(html, treeSanitizer: new NullTreeSanitizer());
23-
return div.nodes;
23+
return new List.from(div.nodes);
2424
}
2525

2626
e(String html) => es(html).first;
@@ -177,33 +177,16 @@ class ExceptionContains extends unit.Matcher {
177177
}
178178
}
179179

180-
$(selector) {
181-
return new JQuery(selector);
182-
}
183-
180+
// TODO: Decide if we want this function to be called 'es' or '$'
181+
$(String selector) =>
182+
es(selector);
184183

185184
class GetterSetter {
186185
Getter getter(String key) => null;
187186
Setter setter(String key) => null;
188187
}
189188
var getterSetter = new GetterSetter();
190189

191-
class JQuery extends DelegatingList<Node> {
192-
JQuery([selector]) : super([]) {
193-
if (selector == null) {
194-
// do nothing;
195-
} else if (selector is String) {
196-
addAll(es(selector));
197-
} else if (selector is List) {
198-
addAll(selector);
199-
} else if (selector is Node) {
200-
add(selector);
201-
} else {
202-
throw selector;
203-
}
204-
}
205-
}
206-
207190
_injectify(fn) {
208191
// The function does two things:
209192
// First: if the it() passed a function, we wrap it in

test/core_dom/compiler_spec.dart

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void main() {
157157
});
158158

159159
it('should compile two directives with the same selector', (Logger log) {
160-
var element = $(_.compile('<div two-directives></div>'));
160+
var element = _.compile('<div two-directives></div>');
161161

162162
_.rootScope.apply();
163163

@@ -166,7 +166,7 @@ void main() {
166166

167167
it('should compile a directive that ignores children', (Logger log) {
168168
// The ng-repeat comes first, so it is not ignored, but the children *are*
169-
var element = $(_.compile('<div ng-repeat="i in [1,2]" ignore-children><div two-directives></div></div>'));
169+
var element = _.compile('<div ng-repeat="i in [1,2]" ignore-children><div two-directives></div></div>');
170170

171171
_.rootScope.apply();
172172

@@ -279,7 +279,7 @@ void main() {
279279
}));
280280

281281
it('should create a component with I/O', async(() {
282-
var element = $(_.compile(r'<div><io attr="A" expr="name" ondone="done=true"></io></div>'));
282+
_.compile(r'<div><io attr="A" expr="name" ondone="done=true"></io></div>');
283283
microLeap();
284284

285285
_.rootScope.context['name'] = 'misko';
@@ -297,7 +297,7 @@ void main() {
297297
}));
298298

299299
xit('should should not create any watchers if no attributes are specified', async((Profiler perf) {
300-
var element = $(_.compile(r'<div><io></io></div>'));
300+
_.compile(r'<div><io></io></div>');
301301
microLeap();
302302
_.injector.get(Scope).apply();
303303
// Re-enable once we can publish these numbers
@@ -311,7 +311,7 @@ void main() {
311311

312312
it('should create a component with I/O and "=" binding value should be available', async(() {
313313
_.rootScope.context['name'] = 'misko';
314-
var element = $(_.compile(r'<div><io attr="A" expr="name" ondone="done=true"></io></div>'));
314+
_.compile(r'<div><io attr="A" expr="name" ondone="done=true"></io></div>');
315315
microLeap();
316316

317317
var component = _.rootScope.context['ioComponent'];
@@ -324,8 +324,7 @@ void main() {
324324

325325
it('should create a component with I/O bound to controller and "=" binding value should be available', async(() {
326326
_.rootScope.context['done'] = false;
327-
var element = $(_.compile(r'<div><io-controller attr="A" expr="name" once="name" ondone="done=true"></io-controller></div>'));
328-
327+
_.compile(r'<div><io-controller attr="A" expr="name" once="name" ondone="done=true"></io-controller></div>');
329328

330329
expect(_.injector).toBeDefined();
331330
microLeap();
@@ -360,7 +359,7 @@ void main() {
360359
}));
361360

362361
it('should create a map attribute to controller', async(() {
363-
var element = $(_.compile(r'<div><io-controller attr="{{name}}"></io-controller></div>'));
362+
_.compile(r'<div><io-controller attr="{{name}}"></io-controller></div>');
364363
microLeap();
365364

366365
IoControllerComponent component = _.rootScope.context['ioComponent'];
@@ -377,7 +376,7 @@ void main() {
377376
it('should create a unpublished component with I/O bound to controller and "=" binding value should be available', async(() {
378377
_.rootScope.context['name'] = 'misko';
379378
_.rootScope.context['done'] = false;
380-
var element = $(_.compile(r'<div><unpublished-io-controller attr="A" expr="name" ondone="done=true"></unpublished-io-controller></div>'));
379+
_.compile(r'<div><unpublished-io-controller attr="A" expr="name" ondone="done=true"></unpublished-io-controller></div>');
381380
microLeap();
382381

383382
UnpublishedIoControllerComponent component = _.rootScope.context['ioComponent'];
@@ -398,12 +397,12 @@ void main() {
398397

399398
it('should error on incorrect mapping', async(() {
400399
expect(() {
401-
var element = $(_.compile(r'<div><incorrect-mapping></incorrect-mapping</div>'));
400+
_.compile(r'<div><incorrect-mapping></incorrect-mapping</div>');
402401
}).toThrow("Unknown mapping 'foo\' for attribute 'attr'.");
403402
}));
404403

405404
it('should support filters in attribute expressions', async(() {
406-
var element = $(_.compile(r'''<expr-attr-component expr="'Misko' | hello" one-way="'James' | hello" once="'Chirayu' | hello"></expr-attr-component>'''));
405+
_.compile(r'''<expr-attr-component expr="'Misko' | hello" one-way="'James' | hello" once="'Chirayu' | hello"></expr-attr-component>''');
407406
ExprAttrComponent component = _.rootScope.context['exprAttrComponent'];
408407
_.rootScope.apply();
409408
expect(component.expr).toEqual('Hello, Misko!');
@@ -413,12 +412,12 @@ void main() {
413412

414413
it('should error on non-asignable-mapping', async(() {
415414
expect(() {
416-
var element = $(_.compile(r'<div><non-assignable-mapping></non-assignable-mapping</div>'));
415+
_.compile(r'<div><non-assignable-mapping></non-assignable-mapping</div>');
417416
}).toThrow("Expression '1+2' is not assignable in mapping '@1+2' for attribute 'attr'.");
418417
}));
419418

420419
it('should expose mapped attributes as camel case', async(() {
421-
var element = $(_.compile('<camel-case-map camel-case=G></camel-case-map>'));
420+
_.compile('<camel-case-map camel-case=G></camel-case-map>');
422421
microLeap();
423422
_.rootScope.apply();
424423
var componentScope = _.rootScope.context['camelCase'];
@@ -428,7 +427,7 @@ void main() {
428427
// TODO: This is a terrible test
429428
it('should throw an exception if required directive is missing', async(() {
430429
try {
431-
var element = $(_.compile('<tab local><pane></pane><pane local></pane></tab>'));
430+
_.compile('<tab local><pane></pane><pane local></pane></tab>');
432431
} catch (e) {
433432
var text = '$e';
434433
expect(text).toContain('No provider found for');
@@ -438,7 +437,7 @@ void main() {
438437
}));
439438

440439
it('should publish component controller into the scope', async((NgZone zone) {
441-
var element = $(_.compile(r'<div><publish-me></publish-me></div>'));
440+
var element = _.compile(r'<div><publish-me></publish-me></div>');
442441
microLeap();
443442
_.rootScope.apply();
444443
expect(element).toHaveText('WORKED');
@@ -453,13 +452,13 @@ void main() {
453452
}));
454453

455454
it('should "publish" controller to injector under provided publishTypes', () {
456-
var element = $(_.compile(r'<div publish-types></div>'));
455+
_.compile(r'<div publish-types></div>');
457456
expect(PublishTypesAttrDirective._injector.get(PublishTypesAttrDirective)).
458457
toBe(PublishTypesAttrDirective._injector.get(PublishTypesDirectiveSuperType));
459458
});
460459

461460
it('should allow repeaters over controllers', async((Logger logger) {
462-
var element = $(_.compile(r'<log ng-repeat="i in [1, 2]"></log>'));
461+
_.compile(r'<log ng-repeat="i in [1, 2]"></log>');
463462
_.rootScope.apply();
464463
microLeap();
465464

@@ -481,8 +480,8 @@ void main() {
481480
scope.context['isReady'] = 'ready';
482481
scope.context['logger'] = logger;
483482
scope.context['once'] = null;
484-
var element = $('<attach-detach attr-value="{{isReady}}" expr-value="isReady" once-value="once">{{logger("inner")}}</attach-detach>');
485-
$compile(element, _.injector.get(DirectiveMap))(_.injector.createChild([new Module()..value(Scope, scope)]), element);
483+
var elts = es('<attach-detach attr-value="{{isReady}}" expr-value="isReady" once-value="once">{{logger("inner")}}</attach-detach>');
484+
$compile(elts, _.injector.get(DirectiveMap))(_.injector.createChild([new Module()..value(Scope, scope)]), elts);
486485
expect(logger).toEqual(['new']);
487486

488487
expect(logger).toEqual(['new']);
@@ -506,14 +505,14 @@ void main() {
506505

507506
scope.destroy();
508507
expect(logger).toEqual(['detach']);
509-
expect(element).toHaveText('WORKED');
508+
expect(elts).toHaveText('WORKED');
510509
}));
511510

512511
it('should should not call attach after scope is destroyed', async((Compiler $compile, Logger logger, MockHttpBackend backend) {
513512
backend.whenGET('foo.html').respond('<div>WORKED</div>');
514-
var element = $('<simple-attach></simple-attach>');
513+
var elts = es('<simple-attach></simple-attach>');
515514
var scope = _.rootScope.createChild({});
516-
$compile(element, _.injector.get(DirectiveMap))(_.injector.createChild([new Module()..value(Scope, scope)]), element);
515+
$compile(elts, _.injector.get(DirectiveMap))(_.injector.createChild([new Module()..value(Scope, scope)]), elts);
517516
expect(logger).toEqual(['SimpleAttachComponent']);
518517
scope.destroy();
519518

@@ -539,7 +538,7 @@ void main() {
539538
var c = injector.get(Compiler);
540539
var directives = injector.get(DirectiveMap);
541540
expect(() {
542-
c($('<div></div>'), injector.get(DirectiveMap));
541+
c(es('<div></div>'), injector.get(DirectiveMap));
543542
}).toThrow('Missing selector annotation for MissingSelector');
544543
});
545544

@@ -552,7 +551,7 @@ void main() {
552551
var directives = injector.get(DirectiveMap);
553552

554553
expect(() {
555-
c($('<div></div>'), directives);
554+
c(es('<div></div>'), directives);
556555
}).toThrow('Unknown selector format \'buttonbar button\' for InvalidSelector');
557556
});
558557
});
@@ -561,7 +560,7 @@ void main() {
561560

562561
describe('controller scoping', () {
563562
it('should make controllers available to sibling and child controllers', async((Logger log) {
564-
var element = $(_.compile('<tab local><pane local></pane><pane local></pane></tab>'));
563+
_.compile('<tab local><pane local></pane><pane local></pane></tab>');
565564
microLeap();
566565

567566
expect(log.result()).toEqual('TabComponent-0; LocalAttrDirective-0; PaneComponent-1; LocalAttrDirective-0; PaneComponent-2; LocalAttrDirective-0');
@@ -571,14 +570,14 @@ void main() {
571570
// Getting the parent offsets correct while descending the template is tricky. If we get it wrong, this
572571
// test case will create too many TabCompoenents.
573572

574-
var element = $(_.compile('<div ng-bind="true"><div ignore-children></div><tab local><pane local></pane></tab>'));
573+
_.compile('<div ng-bind="true"><div ignore-children></div><tab local><pane local></pane></tab>');
575574
microLeap();
576575

577576
expect(log.result()).toEqual('Ignore; TabComponent-0; LocalAttrDirective-0; PaneComponent-1; LocalAttrDirective-0');
578577
}));
579578

580579
it('should reuse controllers for transclusions', async((Logger log) {
581-
var element = $(_.compile('<div simple-transclude-in-attach include-transclude>view</div>'));
580+
_.compile('<div simple-transclude-in-attach include-transclude>view</div>');
582581
microLeap();
583582

584583
_.rootScope.apply();
@@ -613,7 +612,7 @@ void main() {
613612
describe('NgDirective', () {
614613
it('should allow creation of a new scope', () {
615614
_.rootScope.context['name'] = 'cover me';
616-
$(_.compile('<div><div my-controller>{{name}}</div></div>'));
615+
_.compile('<div><div my-controller>{{name}}</div></div>');
617616
_.rootScope.apply();
618617
expect(_.rootScope.context['name']).toEqual('cover me');
619618
expect(_.rootElement.text).toEqual('MyController');

0 commit comments

Comments
 (0)