feat(dart/transform): Generate ChangeDetector classes

Use the `ProtoViewDto` created by the render `Compiler` to create a
`ChangeDetectorDefinition`.

From there, generate a subclass of `AbstractChangeDetector` for each
`ChangeDetectorDefinition`.

Run some basic unit tests for the dynamic and JIT change detectors on
pre-generated change detectors.
This commit is contained in:
Tim Blasi
2015-05-14 13:14:45 -07:00
parent 383f0a1f30
commit 8a3b0b366f
15 changed files with 1105 additions and 217 deletions

View File

@ -1,5 +1,8 @@
library bar.ng_deps.dart;
import 'package:angular2/src/change_detection/pregen_proto_change_detector.dart'
as _gen;
import 'bar.dart';
import 'package:angular2/src/core/annotations_impl/annotations.dart';
import 'package:angular2/src/core/annotations_impl/view.dart';
@ -18,3 +21,48 @@ void initReflector(reflector) {
]
});
}
class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
final dynamic _dispatcher;
final _gen.PipeRegistry _pipeRegistry;
final _gen.List<_gen.ProtoRecord> _protos;
final _gen.List<_gen.DirectiveRecord> _directiveRecords;
dynamic _locals = null;
dynamic _context = _gen.ChangeDetectionUtil.uninitialized();
_MyComponent_ChangeDetector0(this._dispatcher, this._pipeRegistry,
this._protos, this._directiveRecords)
: super();
void detectChangesInRecords(throwOnChange) {
var context = null;
var change_context = false;
var isChanged = false;
var currentProto;
var changes = null;
context = _context;
}
void callOnAllChangesDone() {}
void hydrate(context, locals, directives) {
mode = 'ALWAYS_CHECK';
_context = context;
_locals = locals;
}
void dehydrate() {
_context = _gen.ChangeDetectionUtil.uninitialized();
_locals = null;
}
hydrated() =>
!_gen.looseIdentical(_context, _gen.ChangeDetectionUtil.uninitialized());
static _gen.ProtoChangeDetector newProtoChangeDetector(
_gen.PipeRegistry registry, _gen.ChangeDetectorDefinition def) {
return new _gen.PregenProtoChangeDetector(
(a, b, c, d) => new _MyComponent_ChangeDetector0(a, b, c, d), registry,
def);
}
}

View File

@ -1,5 +1,6 @@
library angular2.test.transform.template_compiler.all_tests;
import 'dart:async';
import 'package:barback/barback.dart';
import 'package:angular2/src/dom/html_adapter.dart';
import 'package:angular2/src/transform/common/asset_reader.dart';
@ -18,71 +19,79 @@ void allTests() {
beforeEach(() => setLogger(new PrintLogger()));
it('should parse simple expressions in inline templates.', () async {
var inputPath =
'template_compiler/inline_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
describe('registrations', () {
Future<String> process(AssetId assetId) =>
processTemplates(reader, assetId, generateChangeDetectors: false);
it('should parse simple methods in inline templates.', () async {
var inputPath = 'template_compiler/inline_method_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple expressions in inline templates.', () async {
var inputPath =
'template_compiler/inline_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple expressions in linked templates.', () async {
var inputPath = 'template_compiler/url_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple methods in inline templates.', () async {
var inputPath =
'template_compiler/inline_method_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple methods in linked templates.', () async {
var inputPath = 'template_compiler/url_method_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple expressions in linked templates.', () async {
var inputPath =
'template_compiler/url_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should not generated duplicate getters/setters', () async {
var inputPath = 'template_compiler/duplicate_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/duplicate_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple methods in linked templates.', () async {
var inputPath = 'template_compiler/url_method_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse `View` directives with a single dependency.', () async {
var inputPath = 'template_compiler/one_directive_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/one_directive_files/expected/hello.ng_deps.dart');
it('should not generated duplicate getters/setters', () async {
var inputPath = 'template_compiler/duplicate_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/duplicate_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse `View` directives with a single dependency.', () async {
var inputPath =
'template_compiler/one_directive_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/one_directive_files/expected/hello.ng_deps.dart');
it('should parse `View` directives with a single prefixed dependency.',
() async {
var inputPath = 'template_compiler/with_prefix_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/with_prefix_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
it('should parse `View` directives with a single prefixed dependency.',
() async {
var inputPath = 'template_compiler/with_prefix_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/with_prefix_files/expected/hello.ng_deps.dart');
inputPath = 'template_compiler/with_prefix_files/goodbye.ng_deps.dart';
expected = readFile(
'template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
inputPath = 'template_compiler/with_prefix_files/goodbye.ng_deps.dart';
expected = readFile(
'template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart');
output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
});
}