X Tutup
Skip to content

Commit bdfed9d

Browse files
timrufflesjelbourn
authored andcommitted
docs(core): make naming concrete
I think people new to promises, angular etc will find this example easier to understand with concrete identifiers from a simple use-case. The existing naming could be confused with promise/angular functionality (`promise` in the template, `resolved` etc). Also I made `resolve` private, as then it's clear what we're exposing for the template.
1 parent b9b14dc commit bdfed9d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

modules/angular2/examples/core/pipes/ts/async_pipe/async_pipe_example.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,29 @@ import {bootstrap} from 'angular2/bootstrap';
55
@Component({
66
selector: 'async-example',
77
template: `<div>
8-
<p>Wait for it... {{promise | async}}</p>
9-
<button (click)="clicked()">{{resolved ? 'Reset' : 'Resolve'}}</button>
8+
<p>Wait for it... {{ greeting | async }}</p>
9+
<button (click)="clicked()">{{ arrived ? 'Reset' : 'Resolve' }}</button>
1010
</div>`
1111
})
1212
export class AsyncPipeExample {
13-
resolved: boolean = false;
14-
promise: Promise<string> = null;
15-
resolve: Function = null;
13+
greeting: Promise<string> = null;
14+
arrived: boolean = false;
15+
16+
private resolve: Function = null;
1617

1718
constructor() { this.reset(); }
1819

1920
reset() {
20-
this.resolved = false;
21-
this.promise = new Promise<string>((resolve, reject) => { this.resolve = resolve; });
21+
this.arrived = false;
22+
this.greeting = new Promise<string>((resolve, reject) => { this.resolve = resolve; });
2223
}
2324

2425
clicked() {
25-
if (this.resolved) {
26+
if (this.arrived) {
2627
this.reset();
2728
} else {
28-
this.resolve("resolved!");
29-
this.resolved = true;
29+
this.resolve("hi there!");
30+
this.arrived = true;
3031
}
3132
}
3233
}

0 commit comments

Comments
 (0)
X Tutup