1- import { DynamicProtoChangeDetector , JitProtoChangeDetector } from './proto_change_detector' ;
1+ import { JitProtoChangeDetector } from './jit_proto_change_detector' ;
2+ import { PregenProtoChangeDetector } from './pregen_proto_change_detector' ;
3+ import { DynamicProtoChangeDetector } from './proto_change_detector' ;
24import { PipeFactory , Pipe } from './pipes/pipe' ;
35import { PipeRegistry } from './pipes/pipe_registry' ;
46import { IterableChangesFactory } from './pipes/iterable_changes' ;
@@ -10,9 +12,9 @@ import {LowerCaseFactory} from './pipes/lowercase_pipe';
1012import { JsonPipe } from './pipes/json_pipe' ;
1113import { NullPipeFactory } from './pipes/null_pipe' ;
1214import { ChangeDetection , ProtoChangeDetector , ChangeDetectorDefinition } from './interfaces' ;
13- import { Injectable } from 'angular2/src/di/decorators ' ;
14- import { List , StringMapWrapper } from 'angular2/src/facade/collection' ;
15- import { isPresent , BaseException } from 'angular2/src/facade/lang' ;
15+ import { Inject , Injectable , OpaqueToken , Optional } from 'angular2/di ' ;
16+ import { List , StringMap , StringMapWrapper } from 'angular2/src/facade/collection' ;
17+ import { CONST_EXPR , isPresent , BaseException } from 'angular2/src/facade/lang' ;
1618
1719/**
1820 * Structural diffing for `Object`s and `Map`s.
@@ -66,29 +68,44 @@ export var defaultPipes = {
6668 "json" : json
6769} ;
6870
69- export var preGeneratedProtoDetectors = { } ;
71+ /**
72+ * Map from {@link ChangeDetectorDefinition#id} to a factory method which takes a
73+ * {@link PipeRegistry} and a {@link ChangeDetectorDefinition} and generates a
74+ * {@link ProtoChangeDetector} associated with the definition.
75+ */
76+ // TODO(kegluneq): Use PregenProtoChangeDetectorFactory rather than Function once possible in
77+ // dart2js. See https://github.com/dart-lang/sdk/issues/23630 for details.
78+ export var preGeneratedProtoDetectors : StringMap < string , Function > = { } ;
7079
80+ export const PROTO_CHANGE_DETECTOR_KEY = CONST_EXPR ( new OpaqueToken ( 'ProtoChangeDetectors' ) ) ;
7181
7282/**
7383 * Implements change detection using a map of pregenerated proto detectors.
7484 *
7585 * @exportedAs angular2/change_detection
7686 */
87+ @Injectable ( )
7788export class PreGeneratedChangeDetection extends ChangeDetection {
7889 _dynamicChangeDetection : ChangeDetection ;
7990 _protoChangeDetectorFactories : StringMap < string , Function > ;
8091
81- constructor ( private registry : PipeRegistry , protoChangeDetectors ?) {
92+ constructor ( private registry : PipeRegistry ,
93+ @Inject ( PROTO_CHANGE_DETECTOR_KEY ) @Optional ( )
94+ protoChangeDetectorsForTest ?: StringMap < string , Function > ) {
8295 super ( ) ;
8396 this . _dynamicChangeDetection = new DynamicChangeDetection ( registry ) ;
84- this . _protoChangeDetectorFactories =
85- isPresent ( protoChangeDetectors ) ? protoChangeDetectors : preGeneratedProtoDetectors ;
97+ this . _protoChangeDetectorFactories = isPresent ( protoChangeDetectorsForTest ) ?
98+ protoChangeDetectorsForTest :
99+ preGeneratedProtoDetectors ;
86100 }
87101
102+ static isSupported ( ) : boolean { return PregenProtoChangeDetector . isSupported ( ) ; }
103+
88104 createProtoChangeDetector ( definition : ChangeDetectorDefinition ) : ProtoChangeDetector {
89105 var id = definition . id ;
90106 if ( StringMapWrapper . contains ( this . _protoChangeDetectorFactories , id ) ) {
91- return StringMapWrapper . get ( this . _protoChangeDetectorFactories , id ) ( this . registry ) ;
107+ return StringMapWrapper . get ( this . _protoChangeDetectorFactories , id ) ( this . registry ,
108+ definition ) ;
92109 }
93110 return this . _dynamicChangeDetection . createProtoChangeDetector ( definition ) ;
94111 }
@@ -112,17 +129,19 @@ export class DynamicChangeDetection extends ChangeDetection {
112129}
113130
114131/**
115- * Implements faster change detection, by generating source code.
132+ * Implements faster change detection by generating source code.
116133 *
117134 * This requires `eval()`. For change detection that does not require `eval()`, see
118- * {@link DynamicChangeDetection}.
135+ * {@link DynamicChangeDetection} and { @link PreGeneratedChangeDetection} .
119136 *
120137 * @exportedAs angular2/change_detection
121138 */
122139@Injectable ( )
123140export class JitChangeDetection extends ChangeDetection {
124141 constructor ( public registry : PipeRegistry ) { super ( ) ; }
125142
143+ static isSupported ( ) : boolean { return JitProtoChangeDetector . isSupported ( ) ; }
144+
126145 createProtoChangeDetector ( definition : ChangeDetectorDefinition ) : ProtoChangeDetector {
127146 return new JitProtoChangeDetector ( this . registry , definition ) ;
128147 }
0 commit comments