OLD | NEW |
1 # Lookup maps | 1 # Lookup maps |
2 | 2 |
3 This package contains the definition of `LookupMap`: a simple, but very | 3 This package contains the definition of `LookupMap`: a simple, but very |
4 restricted map. The map can only hold constant keys and the only way to use the | 4 restricted map. The map can only hold constant keys and the only way to use the |
5 map is to retrieve values with a key you already have. Expect for lookup, any | 5 map is to retrieve values with a key you already have. Except for lookup, any |
6 other operation in `Map` (like forEach, keys, values, length, etc) is not | 6 other operation in `Map` (like forEach, keys, values, length, etc) is not |
7 available. | 7 available. |
8 | 8 |
9 Constant `LookupMap`s are understood by dart2js and can be tree-shaken | 9 Constant `LookupMap`s are understood by dart2js and can be tree-shaken |
10 internally: if a key is not used elsewhere in the program, its entry can be | 10 internally: if a key is not used elsewhere in the program, its entry can be |
11 deleted from the map during compilation without changing the program's behavior. | 11 deleted from the map during compilation without changing the program's behavior. |
12 Currently dart2js supports tree-shaking keys that are Type literals, and any | 12 Currently dart2js supports tree-shaking keys that are Type literals, and any |
13 const expression that can only be created with a const constructor. This means | 13 const expression that can only be created with a const constructor. This means |
14 that primitives, Strings, and constant objects that override the `==` operator | 14 that primitives, Strings, and constant objects that override the `==` operator |
15 cannot be tree-shaken. | 15 cannot be tree-shaken. |
16 | 16 |
17 **Note**: this feature is currently experimental in dart2js, we recommend trying | 17 **Note**: this feature is currently experimental in dart2js, we recommend trying |
18 other alternatives before relying on this feature. | 18 other alternatives before relying on this feature. |
19 | 19 |
20 ## Examples | 20 ## Examples |
21 | 21 |
22 `LookupMap` is unlikely going to be useful for individual developers writing | 22 `LookupMap` is unlikely going to be useful for individual developers writing |
23 code by hand. It is mainly intended as a helper utility for frameworks that need | 23 code by hand. It is mainly intended as a helper utility for frameworks that need |
24 to autogenerate data and associate it with a type in the program. For example, | 24 to autogenerate data and associate it with a type in the program. For example, |
25 this can be used by a dependency injection system to record how to create | 25 this can be used by a dependency injection system to record how to create |
26 instances of a given type. A dependency injection framework can store in a | 26 instances of a given type. A dependency injection framework can store in a |
27 `LookupMap` all the information it needs for every injectable type in every | 27 `LookupMap` all the information it needs for every injectable type in every |
28 library and package. When compiling a specific application, dart2js can | 28 library and package. When compiling a specific application, dart2js can |
29 tree-shake the data of types that are not used by the application. Similarly, | 29 tree-shake the data of types that are not used by the application. Similarly, |
30 this can also be used by serialization/deserialization packages that can store | 30 this can also be used by serialization/deserialization packages that can store |
31 in a `LookupMap` the deserialization logic for a given type. | 31 in a `LookupMap` the deserialization logic for a given type. |
OLD | NEW |