docs(toh-6): refactoring of 'add, edit, delete heroes' (#2170)
* docs(toh-6/dart): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
* docs(toh-6/ts): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
Post-Dart-review updates included.
* docs(toh-6): ward tweaks
2016-08-26 17:57:45 -04:00
|
|
|
// #docregion
|
2016-10-29 17:08:54 -04:00
|
|
|
import 'rxjs/add/operator/switchMap';
|
2016-09-25 21:56:12 -04:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2016-08-09 12:38:25 -04:00
|
|
|
import { ActivatedRoute, Params } from '@angular/router';
|
2016-09-25 21:56:12 -04:00
|
|
|
import { Location } from '@angular/common';
|
2016-04-09 00:18:37 -04:00
|
|
|
|
|
|
|
import { Hero } from './hero';
|
|
|
|
import { HeroService } from './hero.service';
|
2016-05-23 04:02:17 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
@Component({
|
2016-09-25 21:51:54 -04:00
|
|
|
moduleId: module.id,
|
2016-04-09 00:18:37 -04:00
|
|
|
selector: 'my-hero-detail',
|
2016-09-25 21:51:54 -04:00
|
|
|
templateUrl: 'hero-detail.component.html',
|
|
|
|
styleUrls: [ 'hero-detail.component.css' ]
|
2016-04-09 00:18:37 -04:00
|
|
|
})
|
2016-08-09 12:38:25 -04:00
|
|
|
export class HeroDetailComponent implements OnInit {
|
docs(toh-6): refactoring of 'add, edit, delete heroes' (#2170)
* docs(toh-6/dart): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
* docs(toh-6/ts): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
Post-Dart-review updates included.
* docs(toh-6): ward tweaks
2016-08-26 17:57:45 -04:00
|
|
|
hero: Hero;
|
2016-04-09 00:18:37 -04:00
|
|
|
|
|
|
|
constructor(
|
2016-05-23 04:02:17 -04:00
|
|
|
private heroService: HeroService,
|
2016-09-25 21:56:12 -04:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private location: Location
|
|
|
|
) {}
|
2016-04-09 00:18:37 -04:00
|
|
|
|
2016-07-27 09:00:59 -04:00
|
|
|
ngOnInit(): void {
|
2016-10-29 17:08:54 -04:00
|
|
|
this.route.params
|
|
|
|
.switchMap((params: Params) => this.heroService.getHero(+params['id']))
|
|
|
|
.subscribe(hero => this.hero = hero);
|
2016-04-09 00:18:37 -04:00
|
|
|
}
|
2016-06-26 13:13:44 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
// #docregion save
|
2016-07-27 09:00:59 -04:00
|
|
|
save(): void {
|
docs(toh-6): refactoring of 'add, edit, delete heroes' (#2170)
* docs(toh-6/dart): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
* docs(toh-6/ts): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
Post-Dart-review updates included.
* docs(toh-6): ward tweaks
2016-08-26 17:57:45 -04:00
|
|
|
this.heroService.update(this.hero)
|
2016-09-25 21:56:12 -04:00
|
|
|
.then(() => this.goBack());
|
2016-04-09 00:18:37 -04:00
|
|
|
}
|
|
|
|
// #enddocregion save
|
docs(toh-6): refactoring of 'add, edit, delete heroes' (#2170)
* docs(toh-6/dart): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
* docs(toh-6/ts): refactoring of 'add, edit, delete heroes'
Refactoring of "add, edit, delete heroes" section of toh-6 from one big
bottom-up step into small independent feature slices, where the user
achieves a "milesone" (i.e., can run the full app) after each feature
section. The section rewrite is shorter and offers a better UX.
Other simplifications:
- Error handling is consistent: in the hero service we log to the
console, everwhere else we just let errors bubble up.
- Hero service methods renamed based on function (create, update)
rather then lower-level implementation (post, put).
- @Output properties have been eliminated (since they weren't
explained).
E2E tests now pass on both the TS and Dart sides.
Post-Dart-review updates included.
* docs(toh-6): ward tweaks
2016-08-26 17:57:45 -04:00
|
|
|
|
|
|
|
goBack(): void {
|
2016-09-25 21:56:12 -04:00
|
|
|
this.location.back();
|
2016-04-09 00:18:37 -04:00
|
|
|
}
|
|
|
|
}
|