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

Unified Diff: src/site/codelabs/darrrt/examples/6-piratebadge/piratebadge.dart

Issue 339243004: Update generated JS for codelab's pirate app. (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: src/site/codelabs/darrrt/examples/6-piratebadge/piratebadge.dart
diff --git a/src/site/codelabs/darrrt/examples/6-piratebadge/piratebadge.dart b/src/site/codelabs/darrrt/examples/6-piratebadge/piratebadge.dart
index d4274306aa2d9dbf23567ec74cfee1f9413e06ca..e550c895884406f4f05d24a20da8df14329de69d 100644
--- a/src/site/codelabs/darrrt/examples/6-piratebadge/piratebadge.dart
+++ b/src/site/codelabs/darrrt/examples/6-piratebadge/piratebadge.dart
@@ -84,28 +84,18 @@ PirateName getBadgeNameFromStorage() {
}
}
-/*
- * A class declaration.
- */
class PirateName {
- // static variables are shared by all instances.
- // Random is a random number generator in dart:math.
static final Random indexGen = new Random();
- // List is a parameterized type. You can declare the type of the objects it contains.
static List<String> names = [];
static List<String> appellations = [];
- // Instance variables. Private variables have names that start with underscore '_'.
String _firstName;
String _appellation;
- // A constructor with two optional, named parameters.
PirateName({String firstName, String appellation}) {
- // Use nextInt to get a random integer from a Random object.
- // Use length to get the number of items in a list.
if (firstName == null) {
_firstName = names[indexGen.nextInt(names.length)];
} else {
@@ -118,23 +108,16 @@ class PirateName {
}
}
- // A named constructor.
PirateName.fromJSON(String jsonString) {
- // JSON is the default implementation of a JSON encoder/decoder.
- // Map is a collection of key-value pairs.
Map storedName = JSON.decode(jsonString);
_firstName = storedName['f'];
_appellation = storedName['a'];
}
- // Fat arrow syntax is shorthand for a one-line function that returns a value.
String toString() => pirateName;
- // A getter provides read access to the member of an object.
- String get jsonString => '{ "f": "$_firstName", "a": "$_appellation" } ';
+ String get jsonString => JSON.encode({"f": _firstName, "a": _appellation});
- // The ternary operator is shorthand for if-then-else.
- // String interpolation lets you easily build strings from other objects.
String get pirateName => _firstName.isEmpty ? '' : '$_firstName the $_appellation';
static Future readyThePirates() {

Powered by Google App Engine
This is Rietveld 408576698