* docs(toh-6/dart): first edition of prose and example code NOTE: this PR depends on #1686. Dart prose and example match TS except that: - No child-to-parent event emission occurs. - Support for Add Hero is added as an unconditional feature of the Heroes view. - http `_post` takes only a name - http `delete` takes only a hero id. - The Dart in-memory-data-service has been dropped in favor of an implementation based on the "standard" `http.testing.MockClient` class. * post-review changes
15 lines
288 B
Dart
15 lines
288 B
Dart
// #docregion
|
|
class Hero {
|
|
final int id;
|
|
String name;
|
|
|
|
Hero(this.id, this.name);
|
|
|
|
factory Hero.fromJson(Map<String, dynamic> hero) =>
|
|
new Hero(_toInt(hero['id']), hero['name']);
|
|
|
|
Map toJson() => {'id': id, 'name': name};
|
|
}
|
|
|
|
int _toInt(id) => id is int ? id : int.parse(id);
|