|
| 1 | +library angular2.src.change_detection.pregen_proto_change_detector; |
| 2 | + |
| 3 | +import 'package:angular2/src/change_detection/coalesce.dart'; |
| 4 | +import 'package:angular2/src/change_detection/directive_record.dart'; |
| 5 | +import 'package:angular2/src/change_detection/interfaces.dart'; |
| 6 | +import 'package:angular2/src/change_detection/pipes/pipe_registry.dart'; |
| 7 | +import 'package:angular2/src/change_detection/proto_change_detector.dart'; |
| 8 | +import 'package:angular2/src/change_detection/proto_record.dart'; |
| 9 | + |
| 10 | +export 'dart:core' show List; |
| 11 | +export 'package:angular2/src/change_detection/abstract_change_detector.dart' |
| 12 | + show AbstractChangeDetector; |
| 13 | +export 'package:angular2/src/change_detection/directive_record.dart' |
| 14 | + show DirectiveIndex, DirectiveRecord; |
| 15 | +export 'package:angular2/src/change_detection/interfaces.dart' |
| 16 | + show ChangeDetector, ChangeDetectorDefinition, ProtoChangeDetector; |
| 17 | +export 'package:angular2/src/change_detection/pipes/pipe_registry.dart' |
| 18 | + show PipeRegistry; |
| 19 | +export 'package:angular2/src/change_detection/proto_record.dart' |
| 20 | + show ProtoRecord; |
| 21 | +export 'package:angular2/src/change_detection/change_detection_util.dart' |
| 22 | + show ChangeDetectionUtil; |
| 23 | +export 'package:angular2/src/facade/lang.dart' show looseIdentical; |
| 24 | + |
| 25 | +typedef ChangeDetector InstantiateMethod(dynamic dispatcher, |
| 26 | + PipeRegistry registry, List<ProtoRecord> protoRecords, |
| 27 | + List<DirectiveRecord> directiveRecords); |
| 28 | + |
| 29 | +/// Implementation of [ProtoChangeDetector] for use by pre-generated change |
| 30 | +/// detectors in Angular 2 Dart. |
| 31 | +/// Classes generated by the `TemplateCompiler` use this. The `export`s above |
| 32 | +/// allow the generated code to `import` a single library and get all |
| 33 | +/// dependencies. |
| 34 | +class PregenProtoChangeDetector extends ProtoChangeDetector { |
| 35 | + /// The [ChangeDetectorDefinition#id]. Strictly informational. |
| 36 | + final String id; |
| 37 | + |
| 38 | + /// Closure used to generate an actual [ChangeDetector]. |
| 39 | + final InstantiateMethod _instantiateMethod; |
| 40 | + |
| 41 | + // [ChangeDetector] dependencies. |
| 42 | + final PipeRegistry _pipeRegistry; |
| 43 | + final List<ProtoRecord> _protoRecords; |
| 44 | + final List<DirectiveRecord> _directiveRecords; |
| 45 | + |
| 46 | + /// Internal ctor. |
| 47 | + PregenProtoChangeDetector._(this.id, this._instantiateMethod, |
| 48 | + this._pipeRegistry, this._protoRecords, this._directiveRecords); |
| 49 | + |
| 50 | + factory PregenProtoChangeDetector(InstantiateMethod instantiateMethod, |
| 51 | + PipeRegistry registry, ChangeDetectorDefinition def) { |
| 52 | + // TODO(kegluneq): Pre-generate these (#2067). |
| 53 | + var recordBuilder = new ProtoRecordBuilder(); |
| 54 | + def.bindingRecords.forEach((b) { |
| 55 | + recordBuilder.add(b, def.variableNames); |
| 56 | + }); |
| 57 | + var protoRecords = coalesce(recordBuilder.records); |
| 58 | + return new PregenProtoChangeDetector._(def.id, instantiateMethod, registry, |
| 59 | + protoRecords, def.directiveRecords); |
| 60 | + } |
| 61 | + |
| 62 | + @override |
| 63 | + instantiate(dynamic dispatcher) => _instantiateMethod( |
| 64 | + dispatcher, _pipeRegistry, _protoRecords, _directiveRecords); |
| 65 | +} |
0 commit comments