10-22.dart
https://www.sourceinsight.com/
https://github.com/Alvin9999/new-pac/wiki/ss%E5%85%8D%E8%B4%B9%E8%B4%A6%E5%8F%B7
https://github.com/gfw-breaker/nogfw/
x
https://docs.nestjs.com/controllers
Dart
https://github.com/angular-examples/quickstart/tree/master
https://angulardart.dev/guide/setup
https://mp.weixin.qq.com/s/xdSYvqSYOXTOCeb89C1uvg
eventsouce
https://developer.mozilla.org/zh-CN/docs/Server-sent_events/EventSource
https://www.cnblogs.com/accordion/p/7764460.html
AngularDart
router
base-href
1. router
2. routes
route paths lib/src/route_paths.dart
route routes.dart (a first route)
Dart as BackEnd
https://zhuanlan.zhihu.com/p/66105609
https://segmentfault.com/a/1190000008427217
对 js/ts 的启 发
0x01
0x02
typescript 中 class 数组,从远程获取数据的初始化
理想中的 Class List
final mockHeroes = <Hero>[
Hero(2, 'sad'),
Hero(11, 'Mr. Nice'),
Hero(12, 'Narco'),
Hero(13, 'Bombasto'),
Hero(14, 'Celeritas'),
Hero(15, 'Magneta'),
Hero(16, 'RubberMan'),
Hero(17, 'Dynama'),
Hero(18, 'Dr IQ'),
Hero(19, 'Magma'),
Hero(20, 'Tornado')
];
后台实际返回的数据
[
{ "id": 11, "name": "Mr. Nice" },
{ "id": 12, "name": "Narco" },
{ "id": 13, "name": "Bombasto" },
{ "id": 14, "name": "Celeritas" },
{ "id": 15, "name": "Magneta" },
{ "id": 16, "name": "RubberMan" },
{ "id": 17, "name": "Dynama" },
{ "id": 18, "name": "Dr IQ" },
{ "id": 19, "name": "Magma" },
{ "id": 20, "name": "Tornado" }
]
不推荐写法
ts
// bad
public heroes: Heroes[] = [];
getHeroes{
this.service.getHeroes().subscribe(
res => {
this.heroes = [...res];
});
}
此时的 heroes
中的元素的类型不是 Heroes
推荐写法
dart
// good
// service
Future<List<Hero>> getAll() async {
try {
final response = await _http.get(_heroesUrl);
final heroes = (_extractData(response) as List)
.map((json) => Hero.fromJson(json))
.toList();
return heroes;
} catch (e) {
throw _handleError(e);
}
}
// hero.dart
class Hero {
final int id;
String name;
Hero(this.id, this.name);
factory Hero.fromJson(Map<String, dynamic> hero) =>
Hero(_toInt(hero['id']), hero['name']);
Map toJson() => {'id': id, 'name': name};
}
int _toInt(id) => id is int ? id : int.parse(id);
ts
// good