This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(directive): Support multiple directives with same selector.
- Loading branch information
Showing
14 changed files
with
196 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,5 @@ | ||
library angular.core.registry; | ||
|
||
import 'package:di/di.dart' show Injector; | ||
|
||
abstract class AnnotationMap<K> { | ||
final Map<K, Type> _map = {}; | ||
|
||
AnnotationMap(Injector injector, MetadataExtractor extractMetadata) { | ||
injector.types.forEach((type) { | ||
extractMetadata(type) | ||
.where((annotation) => annotation is K) | ||
.forEach((annotation) { | ||
_map[annotation] = type; | ||
}); | ||
}); | ||
} | ||
|
||
Type operator[](K annotation) { | ||
var value = _map[annotation]; | ||
if (value == null) throw 'No $annotation found!'; | ||
return value; | ||
} | ||
|
||
void forEach(fn(K, Type)) { | ||
_map.forEach(fn); | ||
} | ||
|
||
List<K> annotationsFor(Type type) { | ||
final res = <K>[]; | ||
forEach((ann, annType) { | ||
if (annType == type) res.add(ann); | ||
}); | ||
return res; | ||
} | ||
} | ||
|
||
abstract class AnnotationsMap<K> { | ||
final Map<K, List<Type>> map = {}; | ||
|
||
AnnotationsMap(Injector injector, MetadataExtractor extractMetadata) { | ||
injector.types.forEach((type) { | ||
extractMetadata(type) | ||
.where((annotation) => annotation is K) | ||
.forEach((annotation) { | ||
map.putIfAbsent(annotation, () => []).add(type); | ||
}); | ||
}); | ||
} | ||
|
||
List operator[](K annotation) { | ||
var value = map[annotation]; | ||
if (value == null) throw 'No $annotation found!'; | ||
return value; | ||
} | ||
|
||
void forEach(fn(K, Type)) { | ||
map.forEach((annotation, types) { | ||
types.forEach((type) { | ||
fn(annotation, type); | ||
}); | ||
}); | ||
} | ||
|
||
List<K> annotationsFor(Type type) { | ||
var res = <K>[]; | ||
forEach((ann, annType) { | ||
if (annType == type) res.add(ann); | ||
}); | ||
return res; | ||
} | ||
} | ||
|
||
abstract class MetadataExtractor { | ||
Iterable call(Type type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
part of angular.core.dom_internal; | ||
|
||
class DirectiveTypeTuple { | ||
final Directive directive; | ||
final Type type; | ||
DirectiveTypeTuple(this.directive, this.type); | ||
toString() => '@$directive#$type'; | ||
} | ||
|
||
@Injectable() | ||
class DirectiveMap extends AnnotationsMap<Directive> { | ||
class DirectiveMap { | ||
final Map<String, List<DirectiveTypeTuple>> map = new HashMap<String, List<DirectiveTypeTuple>>(); | ||
DirectiveSelectorFactory _directiveSelectorFactory; | ||
FormatterMap _formatters; | ||
DirectiveSelector _selector; | ||
|
||
DirectiveMap(Injector injector, | ||
this._formatters, | ||
MetadataExtractor metadataExtractor, | ||
this._directiveSelectorFactory) { | ||
injector.types.forEach((type) { | ||
metadataExtractor(type) | ||
.where((annotation) => annotation is Directive) | ||
.forEach((Directive directive) { | ||
map.putIfAbsent(directive.selector, () => []).add(new DirectiveTypeTuple(directive, type)); | ||
}); | ||
}); | ||
} | ||
|
||
DirectiveSelector get selector { | ||
if (_selector != null) return _selector; | ||
return _selector = _directiveSelectorFactory.selector(this, _formatters); | ||
} | ||
|
||
DirectiveMap(Injector injector, | ||
this._formatters, | ||
MetadataExtractor metadataExtractor, | ||
this._directiveSelectorFactory) | ||
: super(injector, metadataExtractor); | ||
List<DirectiveTypeTuple> operator[](String key) { | ||
var value = map[key]; | ||
if (value == null) throw 'No Directive selector $key found!'; | ||
return value; | ||
} | ||
|
||
void forEach(fn(K, Type)) { | ||
map.forEach((_, types) { | ||
types.forEach((tuple) { | ||
fn(tuple.directive, tuple.type); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.