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

Commit ac92e77

Browse files
chalinthso
authored andcommitted
docs(dev guide): lifecycle-hooks - updated dart/ts code and new dart prose
Mainly copyedits, but also - Dart .jade extends TS .jade file with minor overrides - Significant update of example code (so it matches the ts example in its appearance and behavior). - Tweaks to Dart code. - A few extra/corrected mixin definitions in `_util-fns.jade`.
1 parent ce6c645 commit ac92e77

31 files changed

+660
-406
lines changed

public/_includes/_util-fns.jade

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
//- Mixins and associated functions
22
3+
- var _docsFor = 'ts'; // or 'dart' or 'js'.
4+
5+
mixin ifDocsFor(lang)
6+
if _docsFor.toLowerCase() === lang.toLowerCase()
7+
block
8+
9+
mixin adjExPath(path)
10+
if adjustExamplePath
11+
| #{adjustExamplePath(path)}
12+
else
13+
| #{path}
14+
315
mixin includeShared(filePath, region)
416
- var newPath = translatePath(filePath, region);
517
!=partial(newPath)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// #docplaster
2+
// #docregion
3+
import 'package:angular2/core.dart';
4+
5+
import 'logger_service.dart';
6+
7+
//////////////////
8+
@Component(
9+
selector: 'my-child',
10+
template: '<input [(ngModel)]="hero">')
11+
class ChildComponent {
12+
String hero = 'Magneta';
13+
}
14+
15+
//////////////////////
16+
@Component(
17+
selector: 'after-content',
18+
// #docregion template
19+
template: '''
20+
<div>-- projected content begins --</div>
21+
<ng-content></ng-content>
22+
<div>-- projected content ends --</div>
23+
<p *ngIf="comment != null" class="comment">{{comment}}</p>
24+
'''
25+
// #enddocregion template
26+
)
27+
// #docregion hooks
28+
class AfterContentComponent implements AfterContentChecked, AfterContentInit {
29+
String _prevHero = '';
30+
String comment = '';
31+
32+
// Query for a CONTENT child of type `ChildComponent`
33+
@ContentChild(ChildComponent) ChildComponent contentChild;
34+
35+
// #enddocregion hooks
36+
final LoggerService _logger;
37+
38+
AfterContentComponent(this._logger) {
39+
_logIt('AfterContent constructor');
40+
}
41+
42+
// #docregion hooks
43+
ngAfterContentInit() {
44+
// contentChild is set after the content has been initialized
45+
_logIt('AfterContentInit');
46+
_doSomething();
47+
}
48+
49+
ngAfterContentChecked() {
50+
// contentChild is updated after the content has been checked
51+
if (_prevHero == contentChild?.hero) {
52+
_logIt('AfterContentChecked (no change)');
53+
} else {
54+
_prevHero = contentChild?.hero;
55+
_logIt('AfterContentChecked');
56+
_doSomething();
57+
}
58+
}
59+
// #enddocregion hooks
60+
// #docregion do-something
61+
/// This surrogate for real business logic; sets the `comment`
62+
void _doSomething() {
63+
comment = contentChild.hero.length > 10 ? "That's a long name" : '';
64+
}
65+
// #enddocregion do-something
66+
67+
void _logIt(String method) {
68+
var child = contentChild;
69+
var message = "${method}: ${child?.hero ?? 'no'} child content";
70+
_logger.log(message);
71+
}
72+
// #docregion hooks
73+
// ...
74+
}
75+
// #enddocregion hooks
76+
77+
//////////////
78+
@Component(
79+
selector: 'after-content-parent',
80+
// #docregion parent-template
81+
template: '''
82+
<div class="parent">
83+
<h2>AfterContent</h2>
84+
85+
<div *ngIf="show">
86+
<after-content>
87+
<my-child></my-child>
88+
</after-content>
89+
</div>
90+
91+
<h4>-- AfterContent Logs --</h4>
92+
<p><button (click)="reset()">Reset</button></p>
93+
<div *ngFor="let msg of logs">{{msg}}</div>
94+
</div>
95+
''',
96+
// #enddocregion parent-template
97+
styles: const ['.parent {background: burlywood}'],
98+
providers: const [LoggerService],
99+
directives: const [AfterContentComponent, ChildComponent])
100+
class AfterContentParentComponent {
101+
final LoggerService _logger;
102+
bool show = true;
103+
104+
AfterContentParentComponent(this._logger);
105+
106+
List<String> get logs => _logger.logs;
107+
108+
void reset() {
109+
logs.clear();
110+
// quickly remove and reload AfterViewComponent which recreates it
111+
show = false;
112+
_logger.tick().then((_) { show = true; });
113+
}
114+
115+
}

public/docs/_examples/lifecycle-hooks/dart/lib/after_content_parent.dart

-95
This file was deleted.

0 commit comments

Comments
 (0)