Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 The package now only contains annotations specifying the shape of the | 1 Methods and annotations to specify interoperability with JavaScript APIs. |
| 2 JavaScript API to import into Dart. | |
| 3 | 2 |
| 4 The core implementation is defined directly in Dart2Js, Dartium, and dev_compile r. | 3 #### Passing functions to JavaScript. |
| 4 | |
| 5 If you are passing a Dart function to a JavaScript API, you must wrap it using | |
| 6 `allowInterop` or `allowInteropCaptureThis`. | |
| 7 | |
| 8 ### Examples | |
| 9 | |
| 10 #### Calling methods | |
| 11 | |
| 12 ```dart | |
| 13 // Calls to stringify map to `JSON.stringify(obj)`. | |
|
Jacob
2015/10/15 21:19:03
don't use word map as all examples are about map
kevmoo
2015/10/15 21:51:09
Done.
| |
| 14 @Js("JSON.stringify") | |
| 15 external String stringify(obj); | |
| 16 ``` | |
| 17 | |
| 18 #### Classes and Namespaces | |
| 19 | |
| 20 ```dart | |
| 21 @Js('google.maps') | |
| 22 library maps; | |
| 23 | |
| 24 // Invokes the JavaScript getter `google.maps.map`. | |
| 25 external Map get map; | |
| 26 | |
| 27 // `new Map` invokes JavaScript `new google.maps.Map(location)` | |
| 28 @Js() | |
| 29 class Map { | |
| 30 external Map(Location location); | |
| 31 external Location getLocation(); | |
| 32 } | |
| 33 | |
| 34 // `new Location(...)` invokes JavaScript `new google.maps.LatLng(...)` | |
| 35 // | |
| 36 // We recommend against using custom JavaScript names whenever | |
| 37 // possible. It is easier for users if the JavaScript names and Dart names | |
| 38 // are consistent. | |
| 39 @Js("LatLng") | |
| 40 class Location { | |
| 41 external Location(num lat, num lng); | |
| 42 } | |
| 43 ``` | |
| 44 | |
| 45 #### Maps | |
| 46 | |
| 47 Dart `Map` objects, including literals, are "opaque" in JavaScript. | |
| 48 You must create Dart classes for each of these. | |
| 49 | |
| 50 ```js | |
| 51 // JavaScript | |
| 52 printOptions({responsive: true}); | |
| 53 ``` | |
| 54 | |
| 55 ```dart | |
| 56 // Dart | |
| 57 void main() { | |
| 58 printOptions(new Options(responsive: true)); | |
| 59 } | |
| 60 | |
| 61 @Js() | |
| 62 external printOptions(Options options); | |
| 63 | |
| 64 @Js() | |
| 65 class Options { | |
| 66 external bool get responsive; | |
| 67 | |
| 68 external factory Options({bool responsive}); | |
| 69 } | |
| 70 ``` | |
| 5 | 71 |
| 6 ## Contributing and Filing Bugs | 72 ## Contributing and Filing Bugs |
| 7 | 73 |
| 8 Please file bugs and features requests on the [Github issue tracker](https://git hub.com/dart-lang/js-interop/issues). | 74 Please file bugs and features requests on the [Github issue tracker](https://git hub.com/dart-lang/js-interop/issues). |
| 9 | 75 |
| 10 We also love and accept community contributions, from API suggestions to pull re quests. | 76 We also love and accept community contributions, from API suggestions to pull re quests. |
| 11 Please file an issue before beginning work so we can discuss the design and impl ementation. | 77 Please file an issue before beginning work so we can discuss the design and impl ementation. |
| 12 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. | 78 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. |
| 13 | 79 |
| 14 All we require is that you sign the | 80 Code contributors must sign the |
| 15 [Google Individual Contributor License Agreement](https://developers.google.com/ open-source/cla/individual?csw=1). | 81 [Google Individual Contributor License Agreement](https://developers.google.com/ open-source/cla/individual?csw=1). |
| OLD | NEW |