| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.async; | 5 part of dart.async; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Indicates that loading of [libraryName] is deferred. | 8 * Indicates that loading of [libraryName] is deferred. |
| 9 * | 9 * |
| 10 * Applies to library imports, when used as metadata. | 10 * This class is deprecated. Instead use the syntax: |
| 11 * `import "library.dart" deferred as prefix;` |
| 11 * | 12 * |
| 12 * Example usage: | 13 * Read more about the new syntax |
| 13 * | 14 * [here](https://www.dartlang.org/docs/spec/deferred-loading.html). |
| 14 * @lazy | |
| 15 * import 'foo.dart' as foo; | |
| 16 * | |
| 17 * const lazy = const DeferredLibrary('com.example.foo'); | |
| 18 * | |
| 19 * void main() { | |
| 20 * foo.method(); // Throws a NoSuchMethodError, foo is not loaded yet. | |
| 21 * lazy.load().then(onFooLoaded); | |
| 22 * } | |
| 23 * | |
| 24 * void onFooLoaded(_) { | |
| 25 * foo.method(); | |
| 26 * } | |
| 27 */ | 15 */ |
| 28 class DeferredLibrary { | 16 class DeferredLibrary { |
| 29 final String libraryName; | 17 final String libraryName; |
| 30 final String uri; | 18 final String uri; |
| 31 | 19 |
| 32 const DeferredLibrary(this.libraryName, {this.uri}); | 20 const DeferredLibrary(this.libraryName, {this.uri}); |
| 33 | 21 |
| 34 /** | 22 /** |
| 35 * Ensure that [libraryName] has been loaded. | 23 * Ensure that [libraryName] has been loaded. |
| 36 * | 24 * |
| 37 * If the library fails to load, the Future will complete with a | 25 * If the library fails to load, the Future will complete with a |
| 38 * DeferredLoadException. | 26 * DeferredLoadException. |
| 39 */ | 27 */ |
| 40 external Future<Null> load(); | 28 external Future<Null> load(); |
| 41 } | 29 } |
| 42 | 30 |
| 43 /** | 31 /** |
| 44 * Thrown when a deferred library fails to load. | 32 * Thrown when a deferred library fails to load. |
| 45 */ | 33 */ |
| 46 class DeferredLoadException implements Exception { | 34 class DeferredLoadException implements Exception { |
| 47 DeferredLoadException(String this._s); | 35 DeferredLoadException(String this._s); |
| 48 String toString() => "DeferredLoadException: '$_s'"; | 36 String toString() => "DeferredLoadException: '$_s'"; |
| 49 final String _s; | 37 final String _s; |
| 50 } | 38 } |
| OLD | NEW |