| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 4 |
| 5 /** | 5 /** |
| 6 * This defines a class for loading locale data incrementally from | 6 * This defines a class for loading locale data incrementally from |
| 7 * an external source as JSON. The external sources expected are either | 7 * an external source as JSON. The external sources expected are either |
| 8 * local files or via HTTP request. | 8 * local files or via HTTP request. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 /** | 35 /** |
| 36 * Given a piece of remote data, apply [_creationFunction] to it to | 36 * Given a piece of remote data, apply [_creationFunction] to it to |
| 37 * convert it into the right form. Typically this means converting it | 37 * convert it into the right form. Typically this means converting it |
| 38 * from a Map into an object form. | 38 * from a Map into an object form. |
| 39 */ | 39 */ |
| 40 Function _creationFunction; | 40 Function _creationFunction; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * The set of available locales. | 43 * The set of available locales. |
| 44 */ | 44 */ |
| 45 Set _availableLocaleSet; | 45 Set availableLocaleSet; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * The constructor. The [uriString] specifies where the data comes | 48 * The constructor. The [uriString] specifies where the data comes |
| 49 * from. The [_creationFunction] creates the appropriate data type | 49 * from. The [_creationFunction] creates the appropriate data type |
| 50 * from the remote data (which typically comes in as a Map). The | 50 * from the remote data (which typically comes in as a Map). The |
| 51 * [keys] lists the set of remotely available locale names so we know which | 51 * [keys] lists the set of remotely available locale names so we know which |
| 52 * things can be fetched without having to check remotely. | 52 * things can be fetched without having to check remotely. |
| 53 */ | 53 */ |
| 54 LazyLocaleData(this._reader, this._creationFunction, List keys) { | 54 LazyLocaleData(this._reader, this._creationFunction, List keys) { |
| 55 map = new Map(); | 55 map = new Map(); |
| 56 availableLocales = keys; | 56 availableLocales = keys; |
| 57 } | 57 availableLocaleSet = new Set.from(availableLocales); |
| 58 | |
| 59 /** The set of available locales. */ | |
| 60 get availableLocaleSet { | |
| 61 if (_availableLocaleSet == null) { | |
| 62 _availableLocaleSet = new Set.from(availableLocales); | |
| 63 } | |
| 64 return _availableLocaleSet; | |
| 65 } | 58 } |
| 66 | 59 |
| 67 /** | 60 /** |
| 68 * Tests if we have data for the locale available. Note that this returns | 61 * Tests if we have data for the locale available. Note that this returns |
| 69 * true even if the data is known to be available remotely but not yet loaded. | 62 * true even if the data is known to be available remotely but not yet loaded. |
| 70 */ | 63 */ |
| 71 bool containsKey(String locale) => availableLocaleSet.contains(locale); | 64 bool containsKey(String locale) => availableLocaleSet.contains(locale); |
| 72 | 65 |
| 73 /** Returns the list of keys/locale names. */ | 66 /** Returns the list of keys/locale names. */ |
| 74 List getKeys() => availableLocales; | 67 List getKeys() => availableLocales; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 104 } |
| 112 | 105 |
| 113 /** | 106 /** |
| 114 * Given a Future [input] whose value is expected to be a string in JSON form, | 107 * Given a Future [input] whose value is expected to be a string in JSON form, |
| 115 * return another future that parses the JSON into a usable format. | 108 * return another future that parses the JSON into a usable format. |
| 116 */ | 109 */ |
| 117 Future jsonData(Future input) { | 110 Future jsonData(Future input) { |
| 118 return input.transform( (response) => JSON.parse(response)); | 111 return input.transform( (response) => JSON.parse(response)); |
| 119 } | 112 } |
| 120 } | 113 } |
| OLD | NEW |