OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library initialize.static_loader; | 4 library initialize.static_loader; |
5 | 5 |
6 import 'dart:collection' show Queue; | 6 import 'dart:collection' show Queue; |
7 import 'package:initialize/initialize.dart'; | 7 import 'package:initialize/initialize.dart'; |
8 | 8 |
9 /// This represents an annotation/declaration pair. | 9 /// This represents an annotation/declaration pair. |
10 class InitEntry<T> { | 10 class InitEntry<T> { |
11 /// The annotation instance. | 11 /// The annotation instance. |
12 final Initializer<T> meta; | 12 final Initializer<T> meta; |
13 | 13 |
14 /// The target of the annotation to pass to initialize. | 14 /// The target of the annotation to pass to initialize. |
15 final T target; | 15 final T target; |
16 | 16 |
17 InitEntry(this.meta, this.target); | 17 InitEntry(this.meta, this.target); |
18 } | 18 } |
19 | 19 |
20 /// Set of initializers that are invoked by `run`. This is initialized with | 20 /// Set of initializers that are invoked by `run`. This is initialized with |
21 /// code automatically generated by the transformer. | 21 /// code automatically generated by the transformer. |
22 Queue<InitEntry> initializers = new Queue<InitEntry>(); | 22 Queue<InitEntry> initializers = new Queue<InitEntry>(); |
23 | 23 |
24 /// Returns initializer functions matching the supplied filters and removes them | 24 /// Returns initializer functions matching the supplied filters and removes them |
25 /// from `initializers` so they won't be ran again. | 25 /// from `initializers` so they won't be ran again. |
26 Queue<Function> loadInitializers( | 26 Queue<Function> loadInitializers( |
27 {List<Type> typeFilter, InitializerFilter customFilter}) { | 27 {List<Type> typeFilter, InitializerFilter customFilter, Uri from}) { |
| 28 if (from != null) { |
| 29 throw 'The `from` option is not supported in deploy mode.'; |
| 30 } |
28 Queue<Function> result = new Queue<Function>(); | 31 Queue<Function> result = new Queue<Function>(); |
29 | 32 |
30 var matchesFilters = (initializer) { | 33 var matchesFilters = (initializer) { |
31 if (typeFilter != null && | 34 if (typeFilter != null && |
32 !typeFilter.any((t) => initializer.meta.runtimeType == t)) { | 35 !typeFilter.any((t) => initializer.meta.runtimeType == t)) { |
33 return false; | 36 return false; |
34 } | 37 } |
35 if (customFilter != null && !customFilter(initializer.meta)) { | 38 if (customFilter != null && !customFilter(initializer.meta)) { |
36 return false; | 39 return false; |
37 } | 40 } |
38 return true; | 41 return true; |
39 }; | 42 }; |
40 | 43 |
41 result.addAll(initializers | 44 result.addAll(initializers |
42 .where(matchesFilters) | 45 .where(matchesFilters) |
43 .map((i) => () => i.meta.initialize(i.target))); | 46 .map((i) => () => i.meta.initialize(i.target))); |
44 | 47 |
45 initializers.removeWhere(matchesFilters); | 48 initializers.removeWhere(matchesFilters); |
46 | 49 |
47 return result; | 50 return result; |
48 } | 51 } |
OLD | NEW |