Slide 1

Slide 1 text

Using in an

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

- Fabian Gosebrink

Slide 4

Slide 4 text

- Fabian Gosebrink - just now

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

What the f*** is in there???

Slide 8

Slide 8 text

How does that feature work?!?!

Slide 9

Slide 9 text

How can we test this?

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Using

Slide 16

Slide 16 text

Fabian Gosebrink https://offering.solutions Google Developer Expert Microsoft MVP Pluralsight Author

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

#1

Slide 23

Slide 23 text

#1

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

export class ContentComponent implements OnInit { private readonly service = inject(Service); items: Todo[]; doneItems: Todo[]; ngOnInit() { this.service.getData() .subscribe(data => this.items = data); this.service.detDoneItems() .subscribe(data => this.doneItems = data); } addTodo(item: string) { // ... } markAsDone(item: Todo) { // ... } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Slide 29

Slide 29 text

export class ContentComponent implements OnInit { private readonly service = inject(Service); items: Todo[]; doneItems: Todo[]; ngOnInit() { this.service.getData() .subscribe(data => this.items = data); this.service.detDoneItems() .subscribe(data => this.doneItems = data); } addTodo(item: string) { // ... } markAsDone(item: Todo) { // ... } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 private readonly service = inject(Service); export class ContentComponent implements OnInit { 1 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22

Slide 30

Slide 30 text

export class ContentComponent implements OnInit { private readonly service = inject(Service); items: Todo[]; doneItems: Todo[]; ngOnInit() { this.service.getData() .subscribe(data => this.items = data); this.service.detDoneItems() .subscribe(data => this.doneItems = data); } addTodo(item: string) { // ... } markAsDone(item: Todo) { // ... } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 private readonly service = inject(Service); export class ContentComponent implements OnInit { 1 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 items: Todo[]; doneItems: Todo[]; export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 4 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22

Slide 31

Slide 31 text

export class ContentComponent implements OnInit { private readonly service = inject(Service); items: Todo[]; doneItems: Todo[]; ngOnInit() { this.service.getData() .subscribe(data => this.items = data); this.service.detDoneItems() .subscribe(data => this.doneItems = data); } addTodo(item: string) { // ... } markAsDone(item: Todo) { // ... } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 private readonly service = inject(Service); export class ContentComponent implements OnInit { 1 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 items: Todo[]; doneItems: Todo[]; export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 4 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 this.service.getData() .subscribe(data => this.items = data); export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 8 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22

Slide 32

Slide 32 text

export class ContentComponent implements OnInit { private readonly service = inject(Service); items: Todo[]; doneItems: Todo[]; ngOnInit() { this.service.getData() .subscribe(data => this.items = data); this.service.detDoneItems() .subscribe(data => this.doneItems = data); } addTodo(item: string) { // ... } markAsDone(item: Todo) { // ... } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 private readonly service = inject(Service); export class ContentComponent implements OnInit { 1 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 items: Todo[]; doneItems: Todo[]; export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 4 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 this.service.getData() .subscribe(data => this.items = data); export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 8 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 this.service.detDoneItems() .subscribe(data => this.doneItems = data); export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 11 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22

Slide 33

Slide 33 text

export class ContentComponent implements OnInit { private readonly service = inject(Service); items: Todo[]; doneItems: Todo[]; ngOnInit() { this.service.getData() .subscribe(data => this.items = data); this.service.detDoneItems() .subscribe(data => this.doneItems = data); } addTodo(item: string) { // ... } markAsDone(item: Todo) { // ... } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 private readonly service = inject(Service); export class ContentComponent implements OnInit { 1 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 items: Todo[]; doneItems: Todo[]; export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 4 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 this.service.getData() .subscribe(data => this.items = data); export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 8 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 this.service.detDoneItems() .subscribe(data => this.doneItems = data); export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 11 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 addTodo(item: string) { // ... } export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 15 16 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22

Slide 34

Slide 34 text

export class ContentComponent implements OnInit { private readonly service = inject(Service); items: Todo[]; doneItems: Todo[]; ngOnInit() { this.service.getData() .subscribe(data => this.items = data); this.service.detDoneItems() .subscribe(data => this.doneItems = data); } addTodo(item: string) { // ... } markAsDone(item: Todo) { // ... } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 private readonly service = inject(Service); export class ContentComponent implements OnInit { 1 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 items: Todo[]; doneItems: Todo[]; export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 4 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 this.service.getData() .subscribe(data => this.items = data); export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 8 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 this.service.detDoneItems() .subscribe(data => this.doneItems = data); export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 11 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 addTodo(item: string) { // ... } export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 15 16 17 18 markAsDone(item: Todo) { 19 // ... 20 } 21 } 22 markAsDone(item: Todo) { // ... } export class ContentComponent implements OnInit { 1 private readonly service = inject(Service); 2 3 items: Todo[]; 4 doneItems: Todo[]; 5 6 ngOnInit() { 7 this.service.getData() 8 .subscribe(data => this.items = data); 9 10 this.service.detDoneItems() 11 .subscribe(data => this.doneItems = data); 12 } 13 14 addTodo(item: string) { 15 // ... 16 } 17 18 19 20 21 } 22

Slide 35

Slide 35 text

1 2 3 4 5 6 7 8 9 10 11

Slide 36

Slide 36 text

1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 10
11

Slide 37

Slide 37 text

1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 10
11
1 3 4 5 6 7 8 9 10
11

Slide 38

Slide 38 text

export class TodoListComponent { items = input([]) doneItems = input([]) markAsDone = output(); moveToDone(item: Todo) { this.markAsDone.emit(item); } } 1 2 3 4 5 6 7 8 9 10

Slide 39

Slide 39 text

export class TodoListComponent { items = input([]) doneItems = input([]) markAsDone = output(); moveToDone(item: Todo) { this.markAsDone.emit(item); } } 1 2 3 4 5 6 7 8 9 10 items = input([]) doneItems = input([]) export class TodoListComponent { 1 2 3 4 markAsDone = output(); 5 6 moveToDone(item: Todo) { 7 this.markAsDone.emit(item); 8 } 9 } 10

Slide 40

Slide 40 text

export class TodoListComponent { items = input([]) doneItems = input([]) markAsDone = output(); moveToDone(item: Todo) { this.markAsDone.emit(item); } } 1 2 3 4 5 6 7 8 9 10 items = input([]) doneItems = input([]) export class TodoListComponent { 1 2 3 4 markAsDone = output(); 5 6 moveToDone(item: Todo) { 7 this.markAsDone.emit(item); 8 } 9 } 10 markAsDone = output(); this.markAsDone.emit(item); export class TodoListComponent { 1 items = input([]) 2 doneItems = input([]) 3 4 5 6 moveToDone(item: Todo) { 7 8 } 9 } 10

Slide 41

Slide 41 text

export class TodoListComponent { // Don't do this here // It's presentational! private service = inject(Service); items = input([]) doneItems = input([]) moveToDone(item: Todo) { this.service. ... } } 1 2 3 4 5 6 7 8 9 10 11 12

Slide 42

Slide 42 text

export class TodoListComponent { // Don't do this here // It's presentational! private service = inject(Service); items = input([]) doneItems = input([]) moveToDone(item: Todo) { this.service. ... } } 1 2 3 4 5 6 7 8 9 10 11 12 // Don't do this here // It's presentational! private service = inject(Service); this.service. ... export class TodoListComponent { 1 2 3 4 5 items = input([]) 6 doneItems = input([]) 7 8 moveToDone(item: Todo) { 9 10 } 11 } 12

Slide 43

Slide 43 text

Component Component Component REST Component Component

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

@Component({ selector: 'app-my-doggos', standalone: true, templateUrl: './my-doggos.component.html', styleUrls: ['./my-doggos.component.css'], imports: [AsyncPipe, RouterLink, DatePipe, DecimalPipe, NgFor], }) export class MyDoggosComponent implements OnInit { private readonly store = inject(Store); doggos = this.store.select(getMyDoggos); ngOnInit(): void { this.store.dispatch(DoggosActions.loadMyDoggos()); } deleteDoggo(doggo: Doggo) { this.store.dispatch(DoggosActions.deleteDoggo({ doggo })); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Component Store State Reducer Effects Actions

Slide 57

Slide 57 text

Component Store State Reducer Effects Actions Business Logic

Slide 58

Slide 58 text

@Component({ selector: 'app-my-doggos', standalone: true, templateUrl: './my-doggos.component.html', styleUrls: ['./my-doggos.component.css'], imports: [AsyncPipe, RouterLink, DatePipe, DecimalPipe, NgFor], }) export class MyDoggosComponent implements OnInit { private readonly store = inject(Store); doggos = this.store.select(getMyDoggos); ngOnInit(): void { this.store.dispatch(DoggosActions.loadMyDoggos()); } deleteDoggo(doggo: Doggo) { this.store.dispatch(DoggosActions.deleteDoggo({ doggo })); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Slide 59

Slide 59 text

@Component({ selector: 'app-my-doggos', standalone: true, templateUrl: './my-doggos.component.html', styleUrls: ['./my-doggos.component.css'], imports: [AsyncPipe, RouterLink, DatePipe, DecimalPipe, NgFor], }) export class MyDoggosComponent implements OnInit { private readonly store = inject(Store); doggos = this.store.selectSignal(getMyDoggos); ngOnInit(): void { this.store.dispatch(DoggosActions.loadMyDoggos()); } deleteDoggo(doggo: Doggo) { this.store.dispatch(DoggosActions.deleteDoggo({ doggo })); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Slide 60

Slide 60 text

@Component({ selector: 'app-my-doggos', standalone: true, templateUrl: './my-doggos.component.html', styleUrls: ['./my-doggos.component.css'], imports: [AsyncPipe, RouterLink, DatePipe, DecimalPipe, NgFor], }) export class MyDoggosComponent implements OnInit { private readonly store = inject(Store); doggos = this.store.selectSignal(getMyDoggos); ngOnInit(): void { this.store.dispatch(DoggosActions.loadMyDoggos()); } deleteDoggo(doggo: Doggo) { this.store.dispatch(DoggosActions.deleteDoggo({ doggo })); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 doggos = this.store.selectSignal(getMyDoggos); @Component({ 1 selector: 'app-my-doggos', 2 standalone: true, 3 templateUrl: './my-doggos.component.html', 4 styleUrls: ['./my-doggos.component.css'], 5 imports: [AsyncPipe, RouterLink, DatePipe, DecimalPipe, NgFor], 6 }) 7 export class MyDoggosComponent implements OnInit { 8 private readonly store = inject(Store); 9 10 11 12 ngOnInit(): void { 13 this.store.dispatch(DoggosActions.loadMyDoggos()); 14 } 15 16 deleteDoggo(doggo: Doggo) { 17 this.store.dispatch(DoggosActions.deleteDoggo({ doggo })); 18 } 19 } 20

Slide 61

Slide 61 text

@Injectable() export class TodoEffects { private readonly actions$ = inject(Actions); private readonly todoService = inject(TodoService); loadTodos$ = createEffect(() => this.actions$.pipe( ofType(TodoActions.loadAllTodos), concatMap(() => this.todoService.getItems().pipe( map((todos) => TodoActions.loadAllTodosFinished({ todos })), catchError((error) => of(error)) ) ) ) ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Slide 62

Slide 62 text

@Injectable() export class TodoEffects { private readonly actions$ = inject(Actions); private readonly todoService = inject(TodoService); loadTodos$ = createEffect(() => this.actions$.pipe( ofType(TodoActions.loadAllTodos), concatMap(() => this.todoService.getItems().pipe( map((todos) => TodoActions.loadAllTodosFinished({ todos })), catchError((error) => of(error)) ) ) ) ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 this.todoService.getItems().pipe( @Injectable() 1 export class TodoEffects { 2 private readonly actions$ = inject(Actions); 3 4 private readonly todoService = inject(TodoService); 5 6 loadTodos$ = createEffect(() => 7 this.actions$.pipe( 8 ofType(TodoActions.loadAllTodos), 9 concatMap(() => 10 11 map((todos) => TodoActions.loadAllTodosFinished({ todos })), 12 catchError((error) => of(error)) 13 ) 14 ) 15 ) 16 ); 17 } 18

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

export interface TodoState { items: Todo[]; loading: boolean; } export const initialState: TodoState = { items: [], loading: false, }; export const TodoStore = signalStore( withState(initialState), ); 1 2 3 4 5 6 7 8 9 10 11 12 13

Slide 66

Slide 66 text

export interface TodoState { items: Todo[]; loading: boolean; } export const initialState: TodoState = { items: [], loading: false, }; export const TodoStore = signalStore( withState(initialState), ); 1 2 3 4 5 6 7 8 9 10 11 12 13 export interface TodoState { items: Todo[]; loading: boolean; } 1 2 3 4 5 export const initialState: TodoState = { 6 items: [], 7 loading: false, 8 }; 9 10 export const TodoStore = signalStore( 11 withState(initialState), 12 ); 13

Slide 67

Slide 67 text

export interface TodoState { items: Todo[]; loading: boolean; } export const initialState: TodoState = { items: [], loading: false, }; export const TodoStore = signalStore( withState(initialState), ); 1 2 3 4 5 6 7 8 9 10 11 12 13 export interface TodoState { items: Todo[]; loading: boolean; } 1 2 3 4 5 export const initialState: TodoState = { 6 items: [], 7 loading: false, 8 }; 9 10 export const TodoStore = signalStore( 11 withState(initialState), 12 ); 13 export const initialState: TodoState = { items: [], loading: false, }; export interface TodoState { 1 items: Todo[]; 2 loading: boolean; 3 } 4 5 6 7 8 9 10 export const TodoStore = signalStore( 11 withState(initialState), 12 ); 13

Slide 68

Slide 68 text

export interface TodoState { items: Todo[]; loading: boolean; } export const initialState: TodoState = { items: [], loading: false, }; export const TodoStore = signalStore( withState(initialState), ); 1 2 3 4 5 6 7 8 9 10 11 12 13 export interface TodoState { items: Todo[]; loading: boolean; } 1 2 3 4 5 export const initialState: TodoState = { 6 items: [], 7 loading: false, 8 }; 9 10 export const TodoStore = signalStore( 11 withState(initialState), 12 ); 13 export const initialState: TodoState = { items: [], loading: false, }; export interface TodoState { 1 items: Todo[]; 2 loading: boolean; 3 } 4 5 6 7 8 9 10 export const TodoStore = signalStore( 11 withState(initialState), 12 ); 13 export const TodoStore = signalStore( withState(initialState), ); export interface TodoState { 1 items: Todo[]; 2 loading: boolean; 3 } 4 5 export const initialState: TodoState = { 6 items: [], 7 loading: false, 8 }; 9 10 11 12 13

Slide 69

Slide 69 text

export const TodoStore = signalStore( withState({ /* ... */ }), withMethods((...) => ({ // ... })) ); 1 2 3 4 5 6

Slide 70

Slide 70 text

export const TodoStore = signalStore( withState({ /* ... */ }), withMethods((...) => ({ // ... })) ); 1 2 3 4 5 6 withMethods((...) => ({ // ... })) export const TodoStore = signalStore( 1 withState({ /* ... */ }), 2 3 4 5 ); 6

Slide 71

Slide 71 text

export const TodoStore = signalStore( withState({ /* ... */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos() { // use Todoservice and then patchState(store, { items }); }, })) ); 1 2 3 4 5 6 7 8 9

Slide 72

Slide 72 text

export const TodoStore = signalStore( withState({ /* ... */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos() { // use Todoservice and then patchState(store, { items }); }, })) ); 1 2 3 4 5 6 7 8 9 withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos() { // use Todoservice and then patchState(store, { items }); }, })) export const TodoStore = signalStore( 1 withState({ /* ... */ ), 2 3 4 5 6 7 8 ); 9

Slide 73

Slide 73 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState({ /* state goes here */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), })) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Slide 74

Slide 74 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState({ /* state goes here */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), })) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 5 6 7 8 9 10 11 12 13 14 15 16 17 })) 18 ); 19

Slide 75

Slide 75 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState({ /* state goes here */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), })) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 5 6 7 8 9 10 11 12 13 14 15 16 17 })) 18 ); 19 patchState(store, {loading: true}); export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 loadAllTodos: rxMethod( 5 switchMap(() => { 6 7 8 return todoService.getItems().pipe( 9 tapResponse({ 10 next: (items) => patchState(store, {items}), 11 error: console.error, 12 finalize: () => patchState(store, {loading: false}), 13 }) 14 ); 15 }) 16 ), 17 })) 18 ); 19

Slide 76

Slide 76 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState({ /* state goes here */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), })) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 5 6 7 8 9 10 11 12 13 14 15 16 17 })) 18 ); 19 patchState(store, {loading: true}); export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 loadAllTodos: rxMethod( 5 switchMap(() => { 6 7 8 return todoService.getItems().pipe( 9 tapResponse({ 10 next: (items) => patchState(store, {items}), 11 error: console.error, 12 finalize: () => patchState(store, {loading: false}), 13 }) 14 ); 15 }) 16 ), 17 })) 18 ); 19 return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 loadAllTodos: rxMethod( 5 switchMap(() => { 6 patchState(store, {loading: true}); 7 8 9 10 11 12 13 14 15 }) 16 ), 17 })) 18 ); 19

Slide 77

Slide 77 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState({ /* state goes here */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), })) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 loadAllTodos: rxMethod( switchMap(() => { patchState(store, {loading: true}); return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); }) ), export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 5 6 7 8 9 10 11 12 13 14 15 16 17 })) 18 ); 19 patchState(store, {loading: true}); export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 loadAllTodos: rxMethod( 5 switchMap(() => { 6 7 8 return todoService.getItems().pipe( 9 tapResponse({ 10 next: (items) => patchState(store, {items}), 11 error: console.error, 12 finalize: () => patchState(store, {loading: false}), 13 }) 14 ); 15 }) 16 ), 17 })) 18 ); 19 return todoService.getItems().pipe( tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) ); export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 loadAllTodos: rxMethod( 5 switchMap(() => { 6 patchState(store, {loading: true}); 7 8 9 10 11 12 13 14 15 }) 16 ), 17 })) 18 ); 19 tapResponse({ next: (items) => patchState(store, {items}), error: console.error, finalize: () => patchState(store, {loading: false}), }) export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 loadAllTodos: rxMethod( 5 switchMap(() => { 6 patchState(store, {loading: true}); 7 8 return todoService.getItems().pipe( 9 10 11 12 13 14 ); 15 }) 16 ), 17 })) 18 ); 19

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState({ /* state goes here */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos(store, todoService: TodoService) { ... }, async loadAllTodosByPromise() { patchState(store, { loading: true }); const items = await todoService.getItemsAsPromise(); patchState(store, { items, loading: false }); }, })) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 80

Slide 80 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState({ /* state goes here */ ), withMethods((store, todoService = inject(TodoService)) => ({ loadAllTodos(store, todoService: TodoService) { ... }, async loadAllTodosByPromise() { patchState(store, { loading: true }); const items = await todoService.getItemsAsPromise(); patchState(store, { items, loading: false }); }, })) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 async loadAllTodosByPromise() { patchState(store, { loading: true }); const items = await todoService.getItemsAsPromise(); patchState(store, { items, loading: false }); }, export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState({ /* state goes here */ ), 3 withMethods((store, todoService = inject(TodoService)) => ({ 4 loadAllTodos(store, todoService: TodoService) { ... }, 5 6 7 8 9 10 11 12 13 })) 14 ); 15

Slide 81

Slide 81 text

@Component({ // ... }) export class AppComponent implements OnInit { readonly store = inject(TodoStore); ngOnInit() { this.store.loadAllTodos(); } } 1 2 3 4 5 6 7 8 9 10

Slide 82

Slide 82 text

@Component({ // ... }) export class AppComponent implements OnInit { readonly store = inject(TodoStore); ngOnInit() { this.store.loadAllTodos(); } } 1 2 3 4 5 6 7 8 9 10 readonly store = inject(TodoStore); @Component({ 1 // ... 2 }) 3 export class AppComponent implements OnInit { 4 5 6 ngOnInit() { 7 this.store.loadAllTodos(); 8 } 9 } 10

Slide 83

Slide 83 text

@Component({ // ... }) export class AppComponent implements OnInit { readonly store = inject(TodoStore); ngOnInit() { this.store.loadAllTodos(); } } 1 2 3 4 5 6 7 8 9 10 readonly store = inject(TodoStore); @Component({ 1 // ... 2 }) 3 export class AppComponent implements OnInit { 4 5 6 ngOnInit() { 7 this.store.loadAllTodos(); 8 } 9 } 10 this.store.loadAllTodos(); @Component({ 1 // ... 2 }) 3 export class AppComponent implements OnInit { 4 readonly store = inject(TodoStore); 5 6 ngOnInit() { 7 8 } 9 } 10

Slide 84

Slide 84 text

template: `{{ store.items() }} {{ store.loading() }}`, readonly store = inject(TodoStore); @Component({ 1 // ... 2 3 }) 4 export class AppComponent implements OnInit { 5 6 7 ngOnInit() { 8 this.store.loadAllTodos(); 9 } 10 } 11

Slide 85

Slide 85 text

template: `{{ store.items() }} {{ store.loading() }}`, readonly store = inject(TodoStore); @Component({ 1 // ... 2 3 }) 4 export class AppComponent implements OnInit { 5 6 7 ngOnInit() { 8 this.store.loadAllTodos(); 9 } 10 } 11 @Component({ // ... template: `{{ store.items() }} {{ store.loading() }}`, }) export class AppComponent implements OnInit { readonly store = inject(TodoStore); ngOnInit() { this.store.loadAllTodos(); } } 1 2 3 4 5 6 7 8 9 10 11

Slide 86

Slide 86 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState(initialState), withMethods(/* ... */), withHooks({ onInit({ loadAllTodos }) { loadAllTodos(); }, onDestroy() { console.log('on destroy'); }, }) ); 1 2 3 4 5 6 7 8 9 10 11 12 13

Slide 87

Slide 87 text

export const TodoStore = signalStore( { providedIn: 'root' }, withState(initialState), withMethods(/* ... */), withHooks({ onInit({ loadAllTodos }) { loadAllTodos(); }, onDestroy() { console.log('on destroy'); }, }) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 withHooks({ onInit({ loadAllTodos }) { loadAllTodos(); }, onDestroy() { console.log('on destroy'); }, }) export const TodoStore = signalStore( 1 { providedIn: 'root' }, 2 withState(initialState), 3 withMethods(/* ... */), 4 5 6 7 8 9 10 11 12 ); 13

Slide 88

Slide 88 text

@Component({ // ... }) export class AppComponent implements OnInit { readonly store = inject(TodoStore); ngOnInit() { this.store.loadAllTodos(); } } 1 2 3 4 5 6 7 8 9 10

Slide 89

Slide 89 text

@Component({ // ... }) export class AppComponent { readonly store = inject(TodoStore); } 1 2 3 4 5 6

Slide 90

Slide 90 text

@Component({ // ... }) export class AppComponent { readonly store = inject(TodoStore); // No Logic !!! Yay!!! } 1 2 3 4 5 6 7 8

Slide 91

Slide 91 text

export const TodoStore = signalStore( withState(initialState), withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), withMethods(/* ... */), withHooks(/* ... */) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Slide 92

Slide 92 text

export const TodoStore = signalStore( withState(initialState), withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), withMethods(/* ... */), withHooks(/* ... */) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), export const TodoStore = signalStore( 1 withState(initialState), 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21

Slide 93

Slide 93 text

export const TodoStore = signalStore( withState(initialState), withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), withMethods(/* ... */), withHooks(/* ... */) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), export const TodoStore = signalStore( 1 withState(initialState), 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21 doneCount: computed(() => items().filter((x) => x.done).length), export const TodoStore = signalStore( 1 withState(initialState), 2 3 withComputed(({ items }) => ({ 4 5 undoneCount: computed(() => items().filter((x) => !x.done).length), 6 percentageDone: computed(() => { 7 const done = items().filter((x) => x.done).length; 8 const total = items().length; 9 10 if (total === 0) { 11 return 0; 12 } 13 14 return (done / total) * 100; 15 }), 16 })), 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21

Slide 94

Slide 94 text

export const TodoStore = signalStore( withState(initialState), withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), withMethods(/* ... */), withHooks(/* ... */) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), export const TodoStore = signalStore( 1 withState(initialState), 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21 doneCount: computed(() => items().filter((x) => x.done).length), export const TodoStore = signalStore( 1 withState(initialState), 2 3 withComputed(({ items }) => ({ 4 5 undoneCount: computed(() => items().filter((x) => !x.done).length), 6 percentageDone: computed(() => { 7 const done = items().filter((x) => x.done).length; 8 const total = items().length; 9 10 if (total === 0) { 11 return 0; 12 } 13 14 return (done / total) * 100; 15 }), 16 })), 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21 undoneCount: computed(() => items().filter((x) => !x.done).length), export const TodoStore = signalStore( 1 withState(initialState), 2 3 withComputed(({ items }) => ({ 4 doneCount: computed(() => items().filter((x) => x.done).length), 5 6 percentageDone: computed(() => { 7 const done = items().filter((x) => x.done).length; 8 const total = items().length; 9 10 if (total === 0) { 11 return 0; 12 } 13 14 return (done / total) * 100; 15 }), 16 })), 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21

Slide 95

Slide 95 text

export const TodoStore = signalStore( withState(initialState), withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), withMethods(/* ... */), withHooks(/* ... */) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 withComputed(({ items }) => ({ doneCount: computed(() => items().filter((x) => x.done).length), undoneCount: computed(() => items().filter((x) => !x.done).length), percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), })), export const TodoStore = signalStore( 1 withState(initialState), 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21 doneCount: computed(() => items().filter((x) => x.done).length), export const TodoStore = signalStore( 1 withState(initialState), 2 3 withComputed(({ items }) => ({ 4 5 undoneCount: computed(() => items().filter((x) => !x.done).length), 6 percentageDone: computed(() => { 7 const done = items().filter((x) => x.done).length; 8 const total = items().length; 9 10 if (total === 0) { 11 return 0; 12 } 13 14 return (done / total) * 100; 15 }), 16 })), 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21 undoneCount: computed(() => items().filter((x) => !x.done).length), export const TodoStore = signalStore( 1 withState(initialState), 2 3 withComputed(({ items }) => ({ 4 doneCount: computed(() => items().filter((x) => x.done).length), 5 6 percentageDone: computed(() => { 7 const done = items().filter((x) => x.done).length; 8 const total = items().length; 9 10 if (total === 0) { 11 return 0; 12 } 13 14 return (done / total) * 100; 15 }), 16 })), 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21 percentageDone: computed(() => { const done = items().filter((x) => x.done).length; const total = items().length; if (total === 0) { return 0; } return (done / total) * 100; }), export const TodoStore = signalStore( 1 withState(initialState), 2 3 withComputed(({ items }) => ({ 4 doneCount: computed(() => items().filter((x) => x.done).length), 5 undoneCount: computed(() => items().filter((x) => !x.done).length), 6 7 8 9 10 11 12 13 14 15 16 })), 17 18 withMethods(/* ... */), 19 withHooks(/* ... */) 20 ); 21

Slide 96

Slide 96 text

@Component({ providers: [TodoStore], templates: `
{{ store.doneCount() }} / {{ store.undoneCount() }} {{ store.percentageDone() }}
` }) export class AppComponent implements OnInit { readonly store = inject(TodoStore); } 1 2 3 4 5 6 7 8 9 10 11

Slide 97

Slide 97 text

@Component({ providers: [TodoStore], templates: `
{{ store.doneCount() }} / {{ store.undoneCount() }} {{ store.percentageDone() }}
` }) export class AppComponent implements OnInit { readonly store = inject(TodoStore); } 1 2 3 4 5 6 7 8 9 10 11
{{ store.doneCount() }} / {{ store.undoneCount() }} {{ store.percentageDone() }}
` @Component({ 1 providers: [TodoStore], 2 templates: ` 3 4 5 6 7 }) 8 export class AppComponent implements OnInit { 9 readonly store = inject(TodoStore); 10 } 11

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

src/ |-- feature-a | |-- container | |-- presentational | |-- services | `-- ... |-- feature-b | `-- ... `-- shared |-- services `-- ... 1 2 3 4 5 6 7 8 9 10 11

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

Share code between apps

Slide 112

Slide 112 text

Share code between apps Provide feature to one app

Slide 113

Slide 113 text

Share code between apps Provide feature to one app Multiple Libs = 1 Feature

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

Feature Domain Feature Ui Utils Models, services, state Container Components Presentational Components Utility Functions

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

Feature Domain Feature Ui Utils Models, services, state Container Components Presentational Components Utility Functions

Slide 119

Slide 119 text

Feature Domain Feature Ui Utils Models, services, state Container Components Presentational Components Utility Functions

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

{ providedIn: 'root' }, export const DoggosStore = signalStore( 1 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ()), 4 withMethods( 5 ( ... ) => ({ 6 // Methods 7 }) 8 ), 9 withHooks() 10 ); 11

Slide 123

Slide 123 text

{ providedIn: 'root' }, export const DoggosStore = signalStore( 1 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ()), 4 withMethods( 5 ( ... ) => ({ 6 // Methods 7 }) 8 ), 9 withHooks() 10 ); 11 withComputed((store, authStore = inject(AuthStore)) => ()), export const DoggosStore = signalStore( 1 { providedIn: 'root' }, 2 withState(initialState), 3 4 withMethods( 5 ( ... ) => ({ 6 // Methods 7 }) 8 ), 9 withHooks() 10 ); 11

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 export interface RealTimeState { 3 connectionStatus: ConnectionStatus; 4 } 5 6 export const initialState: RealTimeState = { 7 connectionStatus: 'Not Set', 8 }; 9 10 export const RealTimeStore = signalStore( 11 { providedIn: 'root' }, 12 withState(initialState), 13 withMethods((store) => ({ 14 setConnectionStatus: rxMethod( 15 tap((connectionStatus: ConnectionStatus) => 16 patchState(store, { connectionStatus }) 17 ) 18 ), 19 })), 20 withHooks({ 21 onInit( 22 { setConnectionStatus }, 23 signalRStatusService = inject(SignalRStatusService) 24 ) { 25 setConnectionStatus(signalRStatusService.connectionStatus$); 26 }, 27 }) 28 ); 29

Slide 131

Slide 131 text

export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 export interface RealTimeState { 3 connectionStatus: ConnectionStatus; 4 } 5 6 export const initialState: RealTimeState = { 7 connectionStatus: 'Not Set', 8 }; 9 10 export const RealTimeStore = signalStore( 11 { providedIn: 'root' }, 12 withState(initialState), 13 withMethods((store) => ({ 14 setConnectionStatus: rxMethod( 15 tap((connectionStatus: ConnectionStatus) => 16 patchState(store, { connectionStatus }) 17 ) 18 ), 19 })), 20 withHooks({ 21 onInit( 22 { setConnectionStatus }, 23 signalRStatusService = inject(SignalRStatusService) 24 ) { 25 setConnectionStatus(signalRStatusService.connectionStatus$); 26 }, 27 }) 28 ); 29 export interface RealTimeState { connectionStatus: ConnectionStatus; } export const initialState: RealTimeState = { connectionStatus: 'Not Set', }; export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 3 4 5 6 7 8 9 10 export const RealTimeStore = signalStore( 11 { providedIn: 'root' }, 12 withState(initialState), 13 withMethods((store) => ({ 14 setConnectionStatus: rxMethod( 15 tap((connectionStatus: ConnectionStatus) => 16 patchState(store, { connectionStatus }) 17 ) 18 ), 19 })), 20 withHooks({ 21 onInit( 22 { setConnectionStatus }, 23 signalRStatusService = inject(SignalRStatusService) 24 ) { 25 setConnectionStatus(signalRStatusService.connectionStatus$); 26 }, 27 }) 28 ); 29

Slide 132

Slide 132 text

export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 export interface RealTimeState { 3 connectionStatus: ConnectionStatus; 4 } 5 6 export const initialState: RealTimeState = { 7 connectionStatus: 'Not Set', 8 }; 9 10 export const RealTimeStore = signalStore( 11 { providedIn: 'root' }, 12 withState(initialState), 13 withMethods((store) => ({ 14 setConnectionStatus: rxMethod( 15 tap((connectionStatus: ConnectionStatus) => 16 patchState(store, { connectionStatus }) 17 ) 18 ), 19 })), 20 withHooks({ 21 onInit( 22 { setConnectionStatus }, 23 signalRStatusService = inject(SignalRStatusService) 24 ) { 25 setConnectionStatus(signalRStatusService.connectionStatus$); 26 }, 27 }) 28 ); 29 export interface RealTimeState { connectionStatus: ConnectionStatus; } export const initialState: RealTimeState = { connectionStatus: 'Not Set', }; export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 3 4 5 6 7 8 9 10 export const RealTimeStore = signalStore( 11 { providedIn: 'root' }, 12 withState(initialState), 13 withMethods((store) => ({ 14 setConnectionStatus: rxMethod( 15 tap((connectionStatus: ConnectionStatus) => 16 patchState(store, { connectionStatus }) 17 ) 18 ), 19 })), 20 withHooks({ 21 onInit( 22 { setConnectionStatus }, 23 signalRStatusService = inject(SignalRStatusService) 24 ) { 25 setConnectionStatus(signalRStatusService.connectionStatus$); 26 }, 27 }) 28 ); 29 export const RealTimeStore = signalStore( { providedIn: 'root' }, withState(initialState), withMethods((store) => ({ setConnectionStatus: rxMethod( tap((connectionStatus: ConnectionStatus) => patchState(store, { connectionStatus }) ) ), })), withHooks({ onInit( { setConnectionStatus }, signalRStatusService = inject(SignalRStatusService) ) { setConnectionStatus(signalRStatusService.connectionStatus$); }, }) ); export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 export interface RealTimeState { 3 connectionStatus: ConnectionStatus; 4 } 5 6 export const initialState: RealTimeState = { 7 connectionStatus: 'Not Set', 8 }; 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

Slide 133

Slide 133 text

export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 export interface RealTimeState { 3 connectionStatus: ConnectionStatus; 4 } 5 6 export const initialState: RealTimeState = { 7 connectionStatus: 'Not Set', 8 }; 9 10 export const RealTimeStore = signalStore( 11 { providedIn: 'root' }, 12 withState(initialState), 13 withMethods((store) => ({ 14 setConnectionStatus: rxMethod( 15 tap((connectionStatus: ConnectionStatus) => 16 patchState(store, { connectionStatus }) 17 ) 18 ), 19 })), 20 withHooks({ 21 onInit( 22 { setConnectionStatus }, 23 signalRStatusService = inject(SignalRStatusService) 24 ) { 25 setConnectionStatus(signalRStatusService.connectionStatus$); 26 }, 27 }) 28 ); 29 export interface RealTimeState { connectionStatus: ConnectionStatus; } export const initialState: RealTimeState = { connectionStatus: 'Not Set', }; export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 3 4 5 6 7 8 9 10 export const RealTimeStore = signalStore( 11 { providedIn: 'root' }, 12 withState(initialState), 13 withMethods((store) => ({ 14 setConnectionStatus: rxMethod( 15 tap((connectionStatus: ConnectionStatus) => 16 patchState(store, { connectionStatus }) 17 ) 18 ), 19 })), 20 withHooks({ 21 onInit( 22 { setConnectionStatus }, 23 signalRStatusService = inject(SignalRStatusService) 24 ) { 25 setConnectionStatus(signalRStatusService.connectionStatus$); 26 }, 27 }) 28 ); 29 export const RealTimeStore = signalStore( { providedIn: 'root' }, withState(initialState), withMethods((store) => ({ setConnectionStatus: rxMethod( tap((connectionStatus: ConnectionStatus) => patchState(store, { connectionStatus }) ) ), })), withHooks({ onInit( { setConnectionStatus }, signalRStatusService = inject(SignalRStatusService) ) { setConnectionStatus(signalRStatusService.connectionStatus$); }, }) ); export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; 1 2 export interface RealTimeState { 3 connectionStatus: ConnectionStatus; 4 } 5 6 export const initialState: RealTimeState = { 7 connectionStatus: 'Not Set', 8 }; 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 export type ConnectionStatus = 'On' | 'Off' | 'Reconnecting' | 'Not Set'; export interface RealTimeState { connectionStatus: ConnectionStatus; } export const initialState: RealTimeState = { connectionStatus: 'Not Set', }; export const RealTimeStore = signalStore( { providedIn: 'root' }, withState(initialState), withMethods((store) => ({ setConnectionStatus: rxMethod( tap((connectionStatus: ConnectionStatus) => patchState(store, { connectionStatus }) ) ), })), withHooks({ onInit( { setConnectionStatus }, signalRStatusService = inject(SignalRStatusService) ) { setConnectionStatus(signalRStatusService.connectionStatus$); }, }) ); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

Slide 134

Slide 134 text

No content

Slide 135

Slide 135 text

{ providedIn: 'root' }, export const DoggosStore = signalStore( 1 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 withMethods( 5 () => ({ 6 startListeningToRealtimeDoggoEvents() { 7 signalRService.start(); 8 }, 9 10 stopListeningToRealtimeDoggoEvents() { 11 signalRService.stop(); 12 }, 13 rateDoggoFromRealTime: rxMethod( /* ... */ ), 14 addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), 15 deleteDoggoFromRealTime: rxMethod( /* ... */ ), 16 }) 17 ), 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35

Slide 136

Slide 136 text

{ providedIn: 'root' }, export const DoggosStore = signalStore( 1 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 withMethods( 5 () => ({ 6 startListeningToRealtimeDoggoEvents() { 7 signalRService.start(); 8 }, 9 10 stopListeningToRealtimeDoggoEvents() { 11 signalRService.stop(); 12 }, 13 rateDoggoFromRealTime: rxMethod( /* ... */ ), 14 addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), 15 deleteDoggoFromRealTime: rxMethod( /* ... */ ), 16 }) 17 ), 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35 withMethods( () => ({ startListeningToRealtimeDoggoEvents() { signalRService.start(); }, stopListeningToRealtimeDoggoEvents() { signalRService.stop(); }, rateDoggoFromRealTime: rxMethod( /* ... */ ), addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), deleteDoggoFromRealTime: rxMethod( /* ... */ ), }) ), export const DoggosStore = signalStore( 1 { providedIn: 'root' }, 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35

Slide 137

Slide 137 text

{ providedIn: 'root' }, export const DoggosStore = signalStore( 1 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 withMethods( 5 () => ({ 6 startListeningToRealtimeDoggoEvents() { 7 signalRService.start(); 8 }, 9 10 stopListeningToRealtimeDoggoEvents() { 11 signalRService.stop(); 12 }, 13 rateDoggoFromRealTime: rxMethod( /* ... */ ), 14 addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), 15 deleteDoggoFromRealTime: rxMethod( /* ... */ ), 16 }) 17 ), 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35 withMethods( () => ({ startListeningToRealtimeDoggoEvents() { signalRService.start(); }, stopListeningToRealtimeDoggoEvents() { signalRService.stop(); }, rateDoggoFromRealTime: rxMethod( /* ... */ ), addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), deleteDoggoFromRealTime: rxMethod( /* ... */ ), }) ), export const DoggosStore = signalStore( 1 { providedIn: 'root' }, 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35 startListeningToRealtimeDoggoEvents() { signalRService.start(); }, stopListeningToRealtimeDoggoEvents() { signalRService.stop(); }, rateDoggoFromRealTime: rxMethod( /* ... */ ), addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), deleteDoggoFromRealTime: rxMethod( /* ... */ ), export const DoggosStore = signalStore( 1 { providedIn: 'root' }, 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 withMethods( 5 () => ({ 6 7 8 9 10 11 12 13 14 15 16 }) 17 ), 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35

Slide 138

Slide 138 text

{ providedIn: 'root' }, export const DoggosStore = signalStore( 1 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 withMethods( 5 () => ({ 6 startListeningToRealtimeDoggoEvents() { 7 signalRService.start(); 8 }, 9 10 stopListeningToRealtimeDoggoEvents() { 11 signalRService.stop(); 12 }, 13 rateDoggoFromRealTime: rxMethod( /* ... */ ), 14 addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), 15 deleteDoggoFromRealTime: rxMethod( /* ... */ ), 16 }) 17 ), 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35 withMethods( () => ({ startListeningToRealtimeDoggoEvents() { signalRService.start(); }, stopListeningToRealtimeDoggoEvents() { signalRService.stop(); }, rateDoggoFromRealTime: rxMethod( /* ... */ ), addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), deleteDoggoFromRealTime: rxMethod( /* ... */ ), }) ), export const DoggosStore = signalStore( 1 { providedIn: 'root' }, 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35 startListeningToRealtimeDoggoEvents() { signalRService.start(); }, stopListeningToRealtimeDoggoEvents() { signalRService.stop(); }, rateDoggoFromRealTime: rxMethod( /* ... */ ), addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), deleteDoggoFromRealTime: rxMethod( /* ... */ ), export const DoggosStore = signalStore( 1 { providedIn: 'root' }, 2 withState(initialState), 3 withComputed((store, authStore = inject(AuthStore)) => ({ /* ... */ })), 4 withMethods( 5 () => ({ 6 7 8 9 10 11 12 13 14 15 16 }) 17 ), 18 withHooks({ 19 onInit(store, signalRService = inject(SignalRService)) { 20 const addedDoggo$ = signalRService.doggoEvents.pipe( 21 filter( 22 (event): event is DoggoAddedEvent => event.type === 'doggoadded' 23 ), 24 map(({ doggo }) => doggo) 25 ); 26 const deletedDoggoId$ = signalRService.doggoEvents.pipe( 27 filter( 28 (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' 29 ), 30 map(({ id }) => id) 31 ); 32 const ratedDoggo$ = signalRService.doggoEvents.pipe( 33 filter( 34 (event): event is DoggoRatedEvent => event.type === 'doggorated' 35 onInit(store, signalRService = inject(SignalRService)) { const addedDoggo$ = signalRService.doggoEvents.pipe( filter( (event): event is DoggoAddedEvent => event.type === 'doggoadded' ), map(({ doggo }) => doggo) ); const deletedDoggoId$ = signalRService.doggoEvents.pipe( filter( (event): event is DoggoDeletedEvent => event.type === 'doggodeleted' ), map(({ id }) => id) ); const ratedDoggo$ = signalRService.doggoEvents.pipe( filter( (event): event is DoggoRatedEvent => event.type === 'doggorated' ), map(({ doggo }) => doggo) ); store.addDoggoFromRealTime(addedDoggo$); store.rateDoggoFromRealTime(ratedDoggo$); store.deleteDoggoFromRealTime(deletedDoggoId$); }, }, 9 10 stopListeningToRealtimeDoggoEvents() { 11 signalRService.stop(); 12 }, 13 rateDoggoFromRealTime: rxMethod( /* ... */ ), 14 addDoggoFromRealTime: rxMethod(rxMethod( /* ... */ )), 15 deleteDoggoFromRealTime: rxMethod( /* ... */ ), 16 }) 17 ), 18 withHooks({ 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 }) 44 ); 45

Slide 139

Slide 139 text

No content

Slide 140

Slide 140 text

// my.store.ts const MyStore = signalStore( withMethods((store, myService = inject(MyService)) => ({ doSomething() { myService.doSomething2(); }, }) ); 1 2 3 4 5 6 7 8 9 // my.store.spec.ts 10 beforeEach(() => { 11 TestBed.configureTestingModule({ 12 providers: [ 13 MyStore, 14 { provide: MyService, useValue: { doSomething2: jest.fn() } } 15 ], 16 }); 17 }); 18 19 it('works', () => { 20 const myStore = TestBed.inject(MyStore); 21 const myService = TestBed.inject(MyService); 22 23 myStore.doSomething(); 24 25 expect(myService.doSomething2).toHaveBeenCalled(); 26 }); 27

Slide 141

Slide 141 text

// my.store.ts const MyStore = signalStore( withMethods((store, myService = inject(MyService)) => ({ doSomething() { myService.doSomething2(); }, }) ); 1 2 3 4 5 6 7 8 9 // my.store.spec.ts 10 beforeEach(() => { 11 TestBed.configureTestingModule({ 12 providers: [ 13 MyStore, 14 { provide: MyService, useValue: { doSomething2: jest.fn() } } 15 ], 16 }); 17 }); 18 19 it('works', () => { 20 const myStore = TestBed.inject(MyStore); 21 const myService = TestBed.inject(MyService); 22 23 myStore.doSomething(); 24 25 expect(myService.doSomething2).toHaveBeenCalled(); 26 }); 27 // my.store.spec.ts beforeEach(() => { TestBed.configureTestingModule({ providers: [ MyStore, { provide: MyService, useValue: { doSomething2: jest.fn() } } ], }); }); // my.store.ts 1 const MyStore = signalStore( 2 withMethods((store, myService = inject(MyService)) => ({ 3 doSomething() { 4 myService.doSomething2(); 5 }, 6 }) 7 ); 8 9 10 11 12 13 14 15 16 17 18 19 it('works', () => { 20 const myStore = TestBed.inject(MyStore); 21 const myService = TestBed.inject(MyService); 22 23 myStore.doSomething(); 24 25 expect(myService.doSomething2).toHaveBeenCalled(); 26 }); 27

Slide 142

Slide 142 text

// my.store.ts const MyStore = signalStore( withMethods((store, myService = inject(MyService)) => ({ doSomething() { myService.doSomething2(); }, }) ); 1 2 3 4 5 6 7 8 9 // my.store.spec.ts 10 beforeEach(() => { 11 TestBed.configureTestingModule({ 12 providers: [ 13 MyStore, 14 { provide: MyService, useValue: { doSomething2: jest.fn() } } 15 ], 16 }); 17 }); 18 19 it('works', () => { 20 const myStore = TestBed.inject(MyStore); 21 const myService = TestBed.inject(MyService); 22 23 myStore.doSomething(); 24 25 expect(myService.doSomething2).toHaveBeenCalled(); 26 }); 27 // my.store.spec.ts beforeEach(() => { TestBed.configureTestingModule({ providers: [ MyStore, { provide: MyService, useValue: { doSomething2: jest.fn() } } ], }); }); // my.store.ts 1 const MyStore = signalStore( 2 withMethods((store, myService = inject(MyService)) => ({ 3 doSomething() { 4 myService.doSomething2(); 5 }, 6 }) 7 ); 8 9 10 11 12 13 14 15 16 17 18 19 it('works', () => { 20 const myStore = TestBed.inject(MyStore); 21 const myService = TestBed.inject(MyService); 22 23 myStore.doSomething(); 24 25 expect(myService.doSomething2).toHaveBeenCalled(); 26 }); 27 it('works', () => { const myStore = TestBed.inject(MyStore); const myService = TestBed.inject(MyService); myStore.doSomething(); expect(myService.doSomething2).toHaveBeenCalled(); }); // my.store.ts 1 const MyStore = signalStore( 2 withMethods((store, myService = inject(MyService)) => ({ 3 doSomething() { 4 myService.doSomething2(); 5 }, 6 }) 7 ); 8 9 // my.store.spec.ts 10 beforeEach(() => { 11 TestBed.configureTestingModule({ 12 providers: [ 13 MyStore, 14 { provide: MyService, useValue: { doSomething2: jest.fn() } } 15 ], 16 }); 17 }); 18 19 20 21 22 23 24 25 26 27

Slide 143

Slide 143 text

https://ngrx.io/guide/signals/signal-store/testing

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

- You - since today

Slide 148

Slide 148 text

No content