Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 2951183

Browse files
committed
docs(server-communication): heavily refactored (TS & Dart)
1 parent a4bc455 commit 2951183

27 files changed

+388
-304
lines changed

public/docs/_examples/server-communication/dart/example-config.json

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// #docplaster
2+
// #docregion
3+
import "package:angular2/core.dart" show Component;
4+
5+
import "toh/hero_list_component.dart" show HeroListComponent;
6+
import "wiki/wiki_component.dart" show WikiComponent;
7+
import "wiki/wiki_smart_component.dart" show WikiSmartComponent;
8+
9+
@Component(
10+
selector: "my-app",
11+
template: '''
12+
<hero-list></hero-list>
13+
<my-wiki></my-wiki>
14+
<my-wiki-smart></my-wiki-smart>
15+
''',
16+
// #enddocregion
17+
/*
18+
// #docregion http-providers
19+
providers: const [
20+
// in-memory web api provider
21+
const Provider(BrowserClient,
22+
useFactory: HttpClientBackendServiceFactory, deps: const [])],
23+
// #enddocregion http-providers
24+
*/
25+
// #docregion
26+
directives: const [
27+
HeroListComponent,
28+
WikiComponent,
29+
WikiSmartComponent
30+
])
31+
class AppComponent {}

public/docs/_examples/server-communication/dart/lib/hero_data.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import 'package:http/browser_client.dart';
33
import 'package:http_in_memory_web_api/http_in_memory_web_api.dart';
44

5-
CreateDb createDb = () => {
5+
CreateDb _createDb = () => {
66
'heroes': [
77
{"id": "1", "name": "Windstorm"},
88
{"id": "2", "name": "Bombasto"},
@@ -12,4 +12,4 @@ CreateDb createDb = () => {
1212
};
1313

1414
BrowserClient HttpClientBackendServiceFactory() =>
15-
new HttpClientInMemoryBackendService(createDb);
15+
new HttpClientInMemoryBackendService(_createDb);

public/docs/_examples/server-communication/dart/lib/toh/hero_list_component.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'hero_service.dart';
99
@Component(
1010
selector: 'hero-list',
1111
templateUrl: 'hero_list_component.html',
12-
styles: const ['.error {color:red;}'])
12+
providers: const [HeroService])
1313
// #docregion component
1414
class HeroListComponent implements OnInit {
1515
final HeroService _heroService;

public/docs/_examples/server-communication/dart/lib/toh/hero_list_component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!-- #docregion -->
2+
<h1>Tour of Heroes</h1>
23
<h3>Heroes:</h3>
34
<ul>
45
<li *ngFor="let hero of heroes">

public/docs/_examples/server-communication/dart/lib/toh/hero_service.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class HeroService {
1515
// #enddocregion endpoint, http-get
1616
final BrowserClient _http;
1717

18+
// #docregion ctor
1819
HeroService(this._http);
20+
// #enddocregion ctor
1921

2022
// #docregion methods, error-handling, http-get
2123
Future<List<Hero>> getHeroes() async {
@@ -57,6 +59,7 @@ class HeroService {
5759

5860
Exception _handleError(dynamic e) {
5961
// In a real world app, we might use a remote logging infrastructure
62+
// We'd also dig deeper into the error to get a better message
6063
print(e); // log to console instead
6164
return new Exception('Server error; cause: $e');
6265
}

public/docs/_examples/server-communication/dart/lib/toh/toh_component.dart

Lines changed: 0 additions & 36 deletions
This file was deleted.

public/docs/_examples/server-communication/dart/pubspec.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ dependencies:
1212
jsonpadding: ^0.1.0
1313
stream_transformers: ^0.3.0+3
1414
http_in_memory_web_api: ^0.0.1
15+
# #docregion transformers
1516
transformers:
1617
- angular2:
17-
platform_directives: 'package:angular2/common.dart#CORE_DIRECTIVES'
18-
platform_pipes: 'package:angular2/common.dart#COMMON_PIPES'
18+
platform_directives:
19+
- 'package:angular2/common.dart#CORE_DIRECTIVES'
20+
platform_pipes:
21+
- 'package:angular2/common.dart#COMMON_PIPES'
1922
entry_points: 'web/main.dart'
2023
resolved_identifiers:
2124
BrowserClient: 'package:http/browser_client.dart'
2225
- dart_to_js_script_rewriter
26+
# #enddocregion transformers

public/docs/_examples/server-communication/dart/web/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
<meta charset="UTF-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<link rel="stylesheet" href="styles.css">
9+
<link rel="stylesheet" href="sample.css">
910

1011
<script defer src="main.dart" type="application/dart"></script>
1112
<script defer src="packages/browser/dart.js"></script>
1213
</head>
1314

1415
<body>
15-
<my-toh>ToH Loading...</my-toh>
16-
<my-wiki>Wiki Loading...</my-wiki>
17-
<my-wiki-smart>WikiSmart Loading...</my-wiki-smart>
16+
<my-app>Loading...</my-app>
1817
</body>
1918

2019
</html>
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
// #docregion
2-
import 'package:angular2/platform/browser.dart';
1+
// #docplaster
2+
// #docregion final
3+
import 'package:angular2/core.dart' show Provider;
4+
// #docregion v1
5+
import 'package:angular2/platform/browser.dart' show bootstrap;
6+
// #docregion http-providers
7+
import 'package:http/browser_client.dart' show BrowserClient;
8+
// #enddocregion http-providers
39

4-
import 'package:server_communication/toh/toh_component.dart';
5-
import 'package:server_communication/wiki/wiki_component.dart';
6-
import 'package:server_communication/wiki/wiki_smart_component.dart';
10+
import 'package:server_communication/app_component.dart';
11+
// #enddocregion v1
12+
// #docregion in-mem-web-api-imports
13+
import "package:server_communication/hero_data.dart";
714

8-
main() {
9-
bootstrap(TohComponent);
10-
bootstrap(WikiComponent);
11-
bootstrap(WikiSmartComponent);
15+
// #enddocregion in-mem-web-api-imports
16+
// #docregion in-mem-web-api-providers
17+
void main() {
18+
bootstrap(AppComponent, const [
19+
// in-memory web api provider
20+
const Provider(BrowserClient,
21+
useFactory: HttpClientBackendServiceFactory, deps: const [])
22+
// TODO: drop `deps` once fix lands for
23+
// https://github.com/angular/angular/issues/5266
24+
]);
1225
}
26+
// #enddocregion final, in-mem-web-api-providers
27+
/*
28+
// #docregion v1
29+
30+
void main() {
31+
bootstrap(AppComponent, const [BrowserClient]);
32+
}
33+
// #enddocregion v1
34+
*/

0 commit comments

Comments
 (0)