Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: 2-6-client/lib/common/messages.dart

Issue 1056193003: Rename methods to better match new terminology and get rid of json data file. (Closed) Base URL: https://github.com/dart-lang/one-hour-codelab.git@server2
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « 2-6-client/lib/client/piratesapi.dart ('k') | 2-6-client/lib/common/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library pirate.messages; 5 library pirate.messages;
6 6
7 import 'dart:convert' show JSON; 7 // This class is used to send data back and forth between the client and server.
8 8 // It is automatically serialized and deserialized by the RPC package.
9 class Pirate { 9 class Pirate {
10 String name; 10 String name;
11 String appellation; 11 String appellation;
12 12
13 // A message class must have a default constructor taking no arguments. 13 // A message class must have a default constructor taking no arguments.
14 Pirate(); 14 Pirate();
15 15
16 // It is fine to have other named constructors. 16 // It is fine to have other named constructors.
17 Pirate.fromJSON(String jsonString) {
18 Map storedName = JSON.decode(jsonString);
19 name = storedName['f'];
20 appellation = storedName['a'];
21 }
22
23 Pirate.fromString(String pirateName) { 17 Pirate.fromString(String pirateName) {
24 var parts = pirateName.split(' the '); 18 var parts = pirateName.split(' the ');
25 name = parts[0]; 19 name = parts[0];
26 appellation = parts[1]; 20 appellation = parts[1];
27 } 21 }
28 22
29 String get jsonString => JSON.encode({"f": name, "a": appellation});
30
31 String toString() => name.isEmpty ? '' : '$name the $appellation'; 23 String toString() => name.isEmpty ? '' : '$name the $appellation';
32 } 24 }
OLDNEW
« no previous file with comments | « 2-6-client/lib/client/piratesapi.dart ('k') | 2-6-client/lib/common/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698