mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-12 13:53:03 -05:00
feat(challenge1): modernization
This commit is contained in:
@@ -1,23 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { City } from '../model/city.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CityStore {
|
||||
private cities = new BehaviorSubject<City[]>([]);
|
||||
cities$ = this.cities.asObservable();
|
||||
private cities = signal<City[]>([]);
|
||||
|
||||
addAll(cities: City[]) {
|
||||
this.cities.next(cities);
|
||||
this.cities.set(cities);
|
||||
}
|
||||
|
||||
addOne(student: City) {
|
||||
this.cities.next([...this.cities.value, student]);
|
||||
this.cities.set([...this.cities(), student]);
|
||||
}
|
||||
|
||||
deleteOne(id: number) {
|
||||
this.cities.next(this.cities.value.filter((s) => s.id !== id));
|
||||
this.cities.set(this.cities().filter((s) => s.id !== id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { Student } from '../model/student.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class StudentStore {
|
||||
private students = new BehaviorSubject<Student[]>([]);
|
||||
students$ = this.students.asObservable();
|
||||
public students = signal<Student[]>([]);
|
||||
|
||||
addAll(students: Student[]) {
|
||||
this.students.next(students);
|
||||
this.students.set(students);
|
||||
}
|
||||
|
||||
addOne(student: Student) {
|
||||
this.students.next([...this.students.value, student]);
|
||||
this.students.set([...this.students(), student]);
|
||||
}
|
||||
|
||||
deleteOne(id: number) {
|
||||
this.students.next(this.students.value.filter((s) => s.id !== id));
|
||||
this.students.set(this.students().filter((s) => s.id !== id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { Teacher } from '../model/teacher.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TeacherStore {
|
||||
private teachers = new BehaviorSubject<Teacher[]>([]);
|
||||
teachers$ = this.teachers.asObservable();
|
||||
public teachers = signal<Teacher[]>([]);
|
||||
|
||||
addAll(teachers: Teacher[]) {
|
||||
this.teachers.next(teachers);
|
||||
this.teachers.set(teachers);
|
||||
}
|
||||
|
||||
addOne(teacher: Teacher) {
|
||||
this.teachers.next([...this.teachers.value, teacher]);
|
||||
this.teachers.set([...this.teachers(), teacher]);
|
||||
}
|
||||
|
||||
deleteOne(id: number) {
|
||||
this.teachers.next(this.teachers.value.filter((t) => t.id !== id));
|
||||
this.teachers.set(this.teachers().filter((t) => t.id !== id));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user