@@ -6,32 +6,30 @@ import 'dart:html';
66import 'package:react/react.dart' as react;
77import 'package:react/react_dom.dart' as react_dom;
88
9- /**
10- * Hello,
11- *
12- * This is the Dart portion of the tutorial for the Dart react package.
13- *
14- * We'll go through a simple app that queries the Google Maps API and shows the result to the user.
15- * It also stores the search history and allows the user to reload past queries.
16- *
17- * In this file you'll find the structure and the logic of the app. There is also a `geocodes.html` file which contains
18- * the mount point.
19- *
20- * Be sure that you understand the basic concepts of [React] (http://facebook.github.io/react/) before reading this
21- * tutorial.
22- *
23- * Enjoy!
24- */
9+ /// Hello,
10+ ///
11+ /// This is the Dart portion of the tutorial for the Dart react package.
12+ ///
13+ /// We'll go through a simple app that queries the Google Maps API and shows the result to the user.
14+ /// It also stores the search history and allows the user to reload past queries.
15+ ///
16+ /// In this file you'll find the structure and the logic of the app. There is also a `geocodes.html` file which contains
17+ /// the mount point.
18+ ///
19+ /// Be sure that you understand the basic concepts of [React] (https://reactjs.org/) before reading this
20+ /// tutorial.
21+ ///
22+ /// Enjoy!
2523
2624/// Divide your app into components and conquer!
2725///
28- /// This is the first custom [ Component] .
26+ /// This is the first custom ` Component` .
2927///
3028/// It is just an HTML `<tr>` element displaying a single API response to the user.
3129class _GeocodesResultItem extends react.Component {
3230 /// The only function you must implement in the custom component is [render] .
3331 ///
34- /// Every [ Component] has a map of properties called [Component. props] . It can be specified during creation.
32+ /// Every ` Component` has a map of properties called ` props` . It can be specified during creation.
3533 @override
3634 render () {
3735 return react.tr ({}, [
@@ -42,13 +40,13 @@ class _GeocodesResultItem extends react.Component {
4240 }
4341}
4442
45- /// Now we need to tell ReactJS that our custom [ Component] exists by calling [ registerComponent] .
43+ /// Now we need to tell ReactJS that our custom ` Component` exists by calling ` registerComponent` .
4644///
4745/// As a reward, it gives us a function, that takes the properties and returns our element. You'll see it in action
4846/// shortly.
4947///
50- /// This is the only correct way to create a [ Component] . Do not use the constructor!
51- var geocodesResultItem = react.registerComponent (() => new _GeocodesResultItem ());
48+ /// This is the only correct way to create a ` Component` . Do not use the constructor!
49+ var geocodesResultItem = react.registerComponent (() => _GeocodesResultItem ());
5250
5351/// In this component we'll build an HTML `<table>` element full of the `<tr>` elements generated by
5452/// [_GeocodesResultItem]
@@ -95,13 +93,13 @@ class _GeocodesResultList extends react.Component {
9593 }
9694}
9795
98- var geocodesResultList = react.registerComponent (() => new _GeocodesResultList ());
96+ var geocodesResultList = react.registerComponent (() => _GeocodesResultList ());
9997
100- /// In this [ Component] we'll build a search form.
98+ /// In this ` Component` we'll build a search form.
10199///
102- /// This [ Component] illustrates that:
100+ /// This ` Component` illustrates that:
103101///
104- /// > The functions can be [ Component] parameters _(handy for callbacks)_
102+ /// > The functions can be ` Component` parameters _(handy for callbacks)_
105103///
106104/// > The DOM [Element] s can be accessed using `ref` s.
107105class _GeocodesForm extends react.Component {
@@ -158,16 +156,16 @@ class _GeocodesForm extends react.Component {
158156 /// Handle form submission via `props.onSubmit`
159157 onFormSubmit (react.SyntheticEvent event) {
160158 event.preventDefault ();
161- InputElement inputElement = react_dom.findDOMNode (searchInputInstance);
159+ final inputElement = react_dom.findDOMNode (searchInputInstance);
162160 // The input's value is accessed.
163- var address = inputElement.value;
161+ final address = inputElement.value;
164162 inputElement.value = '' ;
165163 // Call the callback from the parent element is called.
166164 props['submitter' ](address);
167165 }
168166}
169167
170- var geocodesForm = react.registerComponent (() => new _GeocodesForm ());
168+ var geocodesForm = react.registerComponent (() => _GeocodesForm ());
171169
172170/// Renders an HTML `<li>` to be used as a child within the [_GeocodesHistoryList] .
173171class _GeocodesHistoryItem extends react.Component {
@@ -189,7 +187,7 @@ class _GeocodesHistoryItem extends react.Component {
189187 }
190188}
191189
192- var geocodesHistoryItem = react.registerComponent (() => new _GeocodesHistoryItem ());
190+ var geocodesHistoryItem = react.registerComponent (() => _GeocodesHistoryItem ());
193191
194192/// Renders the "history list"
195193///
@@ -203,7 +201,7 @@ class _GeocodesHistoryList extends react.Component {
203201 {
204202 'key' : 'list' ,
205203 },
206- new List .from (props['data' ].keys.map ((key) => geocodesHistoryItem ({
204+ List .from (( props['data' ] as Map ) .keys.map ((key) => geocodesHistoryItem ({
207205 'key' : key,
208206 'query' : props['data' ][key]['query' ],
209207 'status' : props['data' ][key]['status' ],
@@ -214,11 +212,11 @@ class _GeocodesHistoryList extends react.Component {
214212 }
215213}
216214
217- var geocodesHistoryList = react.registerComponent (() => new _GeocodesHistoryList ());
215+ var geocodesHistoryList = react.registerComponent (() => _GeocodesHistoryList ());
218216
219- /// The root [ Component] of our application.
217+ /// The root ` Component` of our application.
220218///
221- /// Introduces [state] . Both [state] and [props] are valid locations to store [ Component] data.
219+ /// Introduces [state] . Both [state] and [props] are valid locations to store ` Component` data.
222220///
223221/// However, there are some key differences to note:
224222///
@@ -228,7 +226,7 @@ var geocodesHistoryList = react.registerComponent(() => new _GeocodesHistoryList
228226///
229227/// > When [state] is changed, the component will re-render.
230228///
231- /// It's a common practice to store the application data in the [state] of the root [ Component] . It will re-render
229+ /// It's a common practice to store the application data in the [state] of the root ` Component` . It will re-render
232230/// every time the state is changed. However, it is not required - you can also use normal variables and re-render
233231/// manually if you wish.
234232///
@@ -247,23 +245,23 @@ class _GeocodesApp extends react.Component {
247245 /// Sends the [addressQuery] to the API and processes the result
248246 newQuery (String addressQuery) async {
249247 // Once the query is being sent, it appears in the history and is given an id.
250- var id = addQueryToHistory (addressQuery);
248+ final id = addQueryToHistory (addressQuery);
251249
252250 // Prepare the URL
253251 addressQuery = Uri .encodeQueryComponent (addressQuery);
254- var path = 'https://maps.googleapis.com/maps/api/geocode/json?address=$addressQuery ' ;
252+ final path = 'https://maps.googleapis.com/maps/api/geocode/json?address=$addressQuery ' ;
255253
256254 try {
257255 // Send the request
258- var raw = await HttpRequest .getString (path);
256+ final raw = await HttpRequest .getString (path);
259257 // Delay the answer 2 more seconds, for test purposes
260- await new Future .delayed (new Duration (seconds: 2 ));
258+ await Future .delayed (Duration (seconds: 2 ));
261259 // Is this the answer to the last request?
262260 if (id == last_id) {
263261 // If yes, query was `OK` and `shown_addresses` are replaced
264262 state['history' ][id]['status' ] = 'OK' ;
265263
266- var data = json.decode (raw);
264+ final data = json.decode (raw);
267265
268266 // Calling `setState` will update the state and then repaint the component.
269267 //
@@ -291,7 +289,7 @@ class _GeocodesApp extends react.Component {
291289
292290 /// Add a new [addressQuery] to the `state.history` Map with its status set to 'pending', then return its `id` .
293291 addQueryToHistory (String addressQuery) {
294- var id = ++ last_id;
292+ final id = ++ last_id;
295293
296294 state['history' ][id] = {'query' : addressQuery, 'status' : 'pending' };
297295
@@ -324,7 +322,7 @@ class _GeocodesApp extends react.Component {
324322 }
325323}
326324
327- var geocodesApp = react.registerComponent (() => new _GeocodesApp ());
325+ var geocodesApp = react.registerComponent (() => _GeocodesApp ());
328326
329327/// And finally, a few magic commands to wire it all up!
330328///
0 commit comments