A software component is a unit of composition with contractually specified interfaces and explicit context dependencies only.
Example of code; Hello world multi languages
Adrian Ferreres Esteller
github: ardiadrianadri
twitter: @ardiadrianadri
A) The component
B) The module
C) The app
The app context is the minimum set of code that we need to bootstrap the app
@Component({
selector: 'my-member',
templateUrl: './memeber.component.html',
styleUrls: ['./memeber.component.css']
})
export class MemberComponent {
@Input()
public member: Member = {
id: '',
title: '',
acceptButton: {
buttonClass: '',
buttonTitle: ''
},
rejectButton: {
buttonClass: '',
buttonTitle: ''
}
};
@Output()
public acceptEvent: EventEmitter<Member> = new EventEmitter<Member>();
@Output()
public rejectEvent: EventEmitter<Member> = new EventEmitter<Member>();
pressAccept() {
this.acceptEvent.emit(this.member);
}
pressReject() {
this.rejectEvent.emit(this.member);
}
}Redux architecture in Angular:
http://blog.ng-book.com/introduction-to-redux-with-typescript-and-angular-2/
On change event
Angular services
Angular pipe
Angular component
Back
Rest communication
Vertical
Horizontal way
@Injectable()
export class HeroesLikeService implements Reducer<Hero[]> {
private _addListHero (
state: Hero[],
action: ActionHeroLike
): Hero[] {
return state.concat(action.payload);
}
private _removeHero (
state: Hero[],
action: ActionHeroLike
): Hero[] {
return state.filter((element: Hero) =>
element.id !== action.payload[0].id);
}
reduce (state: Hero[], action: ActionHeroLike ): Hero[] {
let result: Hero [];
switch (action.type) {
case ActionsListLike.ADD_LIST:
result = this._addListHero(state,action);
break;
case ActionsListLike.ADD_HERO:
result = this._addListHero(state,action);
break;
case ActionsListLike.REMOVE_HERO:
result = this._removeHero(state, action);
break;
}
return result;
}
}Redux Service:
@Injectable()
export class HeroesLikeStore extends Store<Hero[]> {
constructor(
protected _reducer: HeroesLikeService,
@Inject(INITAL_STATE) private _initialState: Hero[],
private _errorManager: ErrorHeroesLike
){
super (_reducer, _initialState, _errorManager);
}
}Store:
@Injectable()
export class FilmService {
constructor(
@Inject(CONFIGURATION_FILMS) private _config: ConfigurationFilm,
private _http: Http
){}
private _mapResponseFilm(response:any): Film[]{
let data: any[] = response.json().results;
return data.map((element: any) => {
let film: Film = {
id: element.id,
title: element.title,
description: element.overview
}
return film;
});
}
getFilms(name: string): Observable<Film[]> {
let url=`${this._config.url}`;
return this._http.get(url)
.map(this._mapResponseFilm)
}
}