Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 Methods and annotations to specify interoperability with JavaScript APIs. | 1 Methods and annotations to specify interoperability with JavaScript APIs. |
| 2 | 2 |
| 3 *Note: This package is beta software.* | 3 *This packages requires Dart SDK 1.13.0.* |
| 4 | 4 |
| 5 *Note: This packages requires Dart SDK `>=1.13.0-dev.7`.* | 5 *This is beta software. Please files [issues].* |
| 6 | 6 |
| 7 ### Adding the dependency | 7 ### Adding the dependency |
| 8 | 8 |
| 9 Add the following to your `pubspec.yaml`: | 9 Add the following to your `pubspec.yaml`: |
| 10 | 10 |
| 11 ```yaml | 11 ```yaml |
| 12 dependencies: | 12 dependencies: |
| 13 js: ^0.6.0-beta | 13 js: ^0.6.0 |
| 14 ``` | 14 ``` |
| 15 | 15 |
| 16 #### Passing functions to JavaScript. | 16 ### Example |
| 17 | |
| 18 If you are passing a Dart function to a JavaScript API, you must wrap it using | |
| 19 `allowInterop` or `allowInteropCaptureThis`. | |
| 20 | |
| 21 ### Examples | |
| 22 | 17 |
| 23 See the [Chart.js Dart API](https://github.com/google/chartjs.dart/) for an | 18 See the [Chart.js Dart API](https://github.com/google/chartjs.dart/) for an |
| 24 end-to-end example. | 19 end-to-end example. |
| 25 | 20 |
| 21 ### Usage | |
| 22 | |
| 26 #### Calling methods | 23 #### Calling methods |
| 27 | 24 |
| 28 ```dart | 25 ```dart |
| 29 // Calls invoke JavaScript `JSON.stringify(obj)`. | 26 // Calls invoke JavaScript `JSON.stringify(obj)`. |
| 30 @JS("JSON.stringify") | 27 @JS("JSON.stringify") |
| 31 external String stringify(obj); | 28 external String stringify(obj); |
| 32 ``` | 29 ``` |
| 33 | 30 |
| 34 #### Classes and Namespaces | 31 #### Classes and Namespaces |
| 35 | 32 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 64 ```js | 61 ```js |
| 65 // JavaScript | 62 // JavaScript |
| 66 printOptions({responsive: true}); | 63 printOptions({responsive: true}); |
| 67 ``` | 64 ``` |
| 68 | 65 |
| 69 If you want to use `printOptions` from Dart, you cannot simply pass a Dart `Map` | 66 If you want to use `printOptions` from Dart, you cannot simply pass a Dart `Map` |
| 70 object – they are are "opaque" in JavaScript. | 67 object – they are are "opaque" in JavaScript. |
| 71 | 68 |
| 72 | 69 |
| 73 Instead, create a Dart class with both the `@JS()` and | 70 Instead, create a Dart class with both the `@JS()` and |
| 74 `@anonymous` annotations. | 71 `@anonymous` annotations. |
|
Siggi Cherem (dart-lang)
2015/11/18 23:30:42
mmm. not sure how to reduce the attention on @anon
| |
| 75 | 72 |
| 76 ```dart | 73 ```dart |
| 77 // Dart | 74 // Dart |
| 78 void main() { | 75 void main() { |
| 79 printOptions(new Options(responsive: true)); | 76 printOptions(new Options(responsive: true)); |
| 80 } | 77 } |
| 81 | 78 |
| 82 @JS() | 79 @JS() |
| 83 external printOptions(Options options); | 80 external printOptions(Options options); |
| 84 | 81 |
| 85 @JS() | 82 @JS() |
| 86 @anonymous | 83 @anonymous |
| 87 class Options { | 84 class Options { |
| 88 external bool get responsive; | 85 external bool get responsive; |
| 89 | 86 |
| 90 external factory Options({bool responsive}); | 87 external factory Options({bool responsive}); |
| 91 } | 88 } |
| 92 ``` | 89 ``` |
| 93 | 90 |
| 91 #### Passing functions to JavaScript. | |
| 92 | |
| 93 If you are passing a Dart function to a JavaScript API, you must wrap it using | |
| 94 `allowInterop` or `allowInteropCaptureThis`. | |
| 95 | |
| 94 ## Contributing and Filing Bugs | 96 ## Contributing and Filing Bugs |
| 95 | 97 |
| 96 Please file bugs and features requests on the [Github issue tracker](https://git hub.com/dart-lang/sdk/issues). | 98 Please file bugs and features requests on the [Github issue tracker][issues]. |
| 97 | 99 |
| 98 We also love and accept community contributions, from API suggestions to pull re quests. | 100 We also love and accept community contributions, from API suggestions to pull re quests. |
| 99 Please file an issue before beginning work so we can discuss the design and impl ementation. | 101 Please file an issue before beginning work so we can discuss the design and impl ementation. |
| 100 We are trying to create issues for all current and future work, so if something there intrigues you (or you need it!) join in on the discussion. | 102 We are trying to create issues for all current and future work, so if something there intrigues you (or you need it!) join in on the discussion. |
| 101 | 103 |
| 102 Code contributors must sign the | 104 Code contributors must sign the |
| 103 [Google Individual Contributor License Agreement](https://developers.google.com/ open-source/cla/individual?csw=1). | 105 [Google Individual Contributor License Agreement](https://developers.google.com/ open-source/cla/individual?csw=1). |
| 106 | |
| 107 [issues]: https://goo.gl/j3rzs0 | |
| OLD | NEW |