Skip to content

Commit fd548ef

Browse files
committed
Refactor application state management by commenting out NGXS store integration and related actions
1 parent 01dea24 commit fd548ef

File tree

9 files changed

+370
-391
lines changed

9 files changed

+370
-391
lines changed

package-lock.json

Lines changed: 241 additions & 264 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@
2424
"packageManager": "npm@10.9.2",
2525
"dependencies": {
2626
"@angular/common": "^21.0.0",
27-
"@angular/compiler": "21.0.2",
28-
"@angular/core": "^21.0.0",
2927
"@angular/forms": "^21.0.0",
3028
"@angular/platform-browser": "^21.0.0",
3129
"@angular/router": "^21.0.0",
32-
"@ngxs/store": "^20.1.0",
3330
"rxjs": "~7.8.0",
3431
"tslib": "^2.3.0"
3532
},
3633
"devDependencies": {
3734
"@angular/build": "^21.0.1",
38-
"@angular/cli": "^21.0.1",
39-
"@angular/compiler-cli": "^21.0.0",
35+
"@angular/cli": "^21.0.3",
36+
"@angular/compiler": "^21.0.3",
37+
"@angular/compiler-cli": "^21.0.3",
38+
"@angular/core": "^21.0.3",
4039
"jsdom": "^27.1.0",
4140
"typescript": "~5.9.2",
4241
"vitest": "^4.0.8"

src/app/app.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import {ApplicationConfig, provideBrowserGlobalErrorListeners} from '@angular/co
22
import {provideRouter} from '@angular/router';
33

44
import {routes} from './app.routes';
5-
import {provideStates, provideStore} from '@ngxs/store';
6-
import {SubstanceState} from './store/substance/substance.state';
75

86
export const appConfig: ApplicationConfig = {
97
providers: [
108
provideBrowserGlobalErrorListeners(),
119
provideRouter(routes),
12-
provideStore(),
13-
provideStates([SubstanceState])
10+
//provideStore(),
11+
//provideStates([SubstanceState])
1412
]
1513
};

src/app/app.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import {Component, inject, signal} from '@angular/core';
1+
import {Component, signal} from '@angular/core';
22
import {RouterOutlet} from '@angular/router';
3-
import {select, Store} from '@ngxs/store';
43
import {SubstanceService} from './service/rest/substance/substance.service';
54
import {firstValueFrom} from 'rxjs';
6-
import {SubstanceAction} from './store/substance/substance.actions';
7-
import {SubstanceState} from './store/substance/substance.state';
85
import {Header} from './components/common/header/header';
96

107
@Component({
@@ -16,18 +13,17 @@ import {Header} from './components/common/header/header';
1613
export class App {
1714
protected readonly title = signal('ANGULAR-TEMPLATE-STANDALONE');
1815

19-
public store = inject(Store);
16+
// public store = inject(Store);
2017

2118
constructor(
2219
private readonly substanceService: SubstanceService) {
2320
void firstValueFrom(substanceService.getAllSubstances$()).then(
2421
substances => {
2522
if (substances && substances.length > 0) {
26-
this.store.dispatch(new SubstanceAction.Init(substances));
23+
// this.store.dispatch(new SubstanceAction.Init(substances));
2724
}
2825
}
2926
).then(() => {
30-
console.log(select(SubstanceState.getSubstances))
3127
})
3228
}
3329
}

src/app/components/substance-inventory-overview/substance-inventory-overview.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import {Component, inject} from '@angular/core';
1+
import {Component} from '@angular/core';
22
import {InventoryService} from '../../service/rest/substance/inventory.service';
33
import {firstValueFrom, map, Observable} from 'rxjs';
44
import {ChemicalSubstanceEntryBean} from '../../obj/bean/ChemicalSubstanceEntryBean';
55
import {AsyncPipe} from '@angular/common';
66
import {ChemicalSubstanceBean} from '../../obj/bean/ChemicalSubstanceBean';
77
import {SubstanceService} from '../../service/rest/substance/substance.service';
88
import {Router, RouterLink} from '@angular/router';
9-
import {Store} from '@ngxs/store';
10-
import {SubstanceState} from '../../store/substance/substance.state';
11-
import {SubstanceAction} from '../../store/substance/substance.actions';
9+
1210
import {QuantityPipe} from '../../pipe/quantity.pipe';
1311
import {Unit} from '../../obj/enum/unit.enum';
1412

@@ -28,12 +26,13 @@ export class SubstanceInventoryOverview {
2826

2927
public substanceMap$: Observable<Map<number, ChemicalSubstanceBean>>;
3028

31-
public substanceEntries$ = inject(Store).select(SubstanceState.getSubstances)
29+
//public substanceEntries$ = inject(Store).select(SubstanceState.getSubstances)
3230

3331
constructor(private readonly inventoryService: InventoryService,
3432
private readonly substanceService: SubstanceService,
3533
private readonly router: Router,
36-
private readonly store: Store) {
34+
// private readonly store: Store
35+
) {
3736
this.allSubstanceEntries$ = this.inventoryService.getAllSubstanceInventoryEntries$();
3837
this.substanceMap$ = this.substanceService.getAllSubstances$().pipe(
3938
map(substances => {
@@ -54,7 +53,7 @@ export class SubstanceInventoryOverview {
5453

5554
async deleteSubstanceEntry(number: number) {
5655
await firstValueFrom(this.inventoryService.deleteSubstanceInventoryEntry$(number));
57-
return firstValueFrom(this.store.dispatch(new SubstanceAction.Remove(number)));
56+
//return firstValueFrom(this.store.dispatch(new SubstanceAction.Remove(number)));
5857
}
5958

6059
navigateToSubstanceCreateEntryPage() {
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
import {ChemicalSubstanceEntryBean} from '../../obj/bean/ChemicalSubstanceEntryBean';
1+
/**
2+
import {ChemicalSubstanceEntryBean} from '../../obj/bean/ChemicalSubstanceEntryBean';
23
3-
export namespace InventoryAction {
4+
export namespace InventoryAction {
45
5-
const PREFIX = '[Inventory]';
6+
const PREFIX = '[Inventory]';
67
7-
export class AddSubstance {
8-
static readonly type = `${PREFIX} Add substance item`;
8+
export class AddSubstance {
9+
static readonly type = `${PREFIX} Add substance item`;
910
10-
constructor(readonly substance: ChemicalSubstanceEntryBean) {
11-
}
12-
}
11+
constructor(readonly substance: ChemicalSubstanceEntryBean) {
12+
}
13+
}
1314
14-
export class RemoveSubstance {
15-
static readonly type = `${PREFIX} Remove substance item`;
15+
export class RemoveSubstance {
16+
static readonly type = `${PREFIX} Remove substance item`;
1617
17-
constructor(readonly substanceId: number) {
18+
constructor(readonly substanceId: number) {
1819
19-
}
20-
}
20+
}
21+
}
2122
22-
export class InitSubstances {
23-
static readonly type = `${PREFIX} Init substance items`;
23+
export class InitSubstances {
24+
static readonly type = `${PREFIX} Init substance items`;
2425
25-
constructor(readonly substances: ChemicalSubstanceEntryBean[]) {
26-
}
27-
}
28-
}
26+
constructor(readonly substances: ChemicalSubstanceEntryBean[]) {
27+
}
28+
}
29+
}
30+
31+
*/
Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
1-
import {Injectable} from '@angular/core';
2-
import {Action, Selector, State, StateContext, StateToken} from '@ngxs/store';
3-
import {InventoryAction} from './inventory.actions';
4-
import {ChemicalSubstanceEntryBean} from '../../obj/bean/ChemicalSubstanceEntryBean';
1+
/**
2+
import {Injectable} from '@angular/core';
3+
import {Action, Selector, State, StateContext, StateToken} from '@ngxs/store';
4+
import {InventoryAction} from './inventory.actions';
5+
import {ChemicalSubstanceEntryBean} from '../../obj/bean/ChemicalSubstanceEntryBean';
56
6-
export interface SubstanceModel {
7-
substances: ChemicalSubstanceEntryBean[];
8-
}
7+
export interface SubstanceModel {
8+
substances: ChemicalSubstanceEntryBean[];
9+
}
910
10-
const DEFAULTS: SubstanceModel = {
11-
substances: []
12-
}
11+
const DEFAULTS: SubstanceModel = {
12+
substances: []
13+
}
1314
14-
const SUBSTANCE_TOKEN = new StateToken<SubstanceModel>('inventory');
15+
const SUBSTANCE_TOKEN = new StateToken<SubstanceModel>('inventory');
1516
16-
@State<SubstanceModel>({
17+
@State<SubstanceModel>({
1718
name: SUBSTANCE_TOKEN,
1819
defaults: DEFAULTS
19-
})
20-
@Injectable()
21-
export class InventoryState {
20+
})
21+
@Injectable()
22+
export class InventoryState {
2223
23-
@Selector()
24+
@Selector()
2425
static getSubstanceEntries(state: SubstanceModel) {
25-
return state.substances;
26+
return state.substances;
2627
}
2728
28-
@Selector()
29+
@Selector()
2930
static getSubstanceEntryById(state: SubstanceModel) {
30-
return (id: number) => state.substances.find(substance => Number(substance.id) === id);
31+
return (id: number) => state.substances.find(substance => Number(substance.id) === id);
3132
}
3233
33-
@Action(InventoryAction.AddSubstance)
34+
@Action(InventoryAction.AddSubstance)
3435
addSubstance(ctx: StateContext<SubstanceModel>, action: InventoryAction.AddSubstance) {
35-
const state = ctx.getState();
36-
ctx.setState({
37-
substances: [...state.substances, action.substance],
38-
});
36+
const state = ctx.getState();
37+
ctx.setState({
38+
substances: [...state.substances, action.substance],
39+
});
3940
}
4041
41-
@Action(InventoryAction.RemoveSubstance)
42+
@Action(InventoryAction.RemoveSubstance)
4243
removeSubstance(ctx: StateContext<SubstanceModel>, action: InventoryAction.RemoveSubstance) {
43-
const state = ctx.getState();
44-
ctx.setState({
45-
substances: state.substances.filter(substance => Number(substance.id) !== action.substanceId),
46-
});
44+
const state = ctx.getState();
45+
ctx.setState({
46+
substances: state.substances.filter(substance => Number(substance.id) !== action.substanceId),
47+
});
4748
}
4849
49-
@Action(InventoryAction.InitSubstances)
50+
@Action(InventoryAction.InitSubstances)
5051
initSubstances(ctx: StateContext<SubstanceModel>, action: InventoryAction.InitSubstances) {
51-
ctx.setState({
52-
substances: action.substances,
53-
});
52+
ctx.setState({
53+
substances: action.substances,
54+
});
5455
}
55-
}
56+
}
57+
58+
*/
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import {ChemicalSubstanceBean} from '../../obj/bean/ChemicalSubstanceBean';
1+
/**
2+
import {ChemicalSubstanceBean} from '../../obj/bean/ChemicalSubstanceBean';
23
3-
export namespace SubstanceAction {
4+
export namespace SubstanceAction {
45
5-
const PREFIX = '[Substance]';
6+
const PREFIX = '[Substance]';
67
7-
export class Add {
8-
static readonly type = `${PREFIX} Add item`;
8+
export class Add {
9+
static readonly type = `${PREFIX} Add item`;
910
10-
constructor(readonly substance: ChemicalSubstanceBean) {
11-
}
12-
}
11+
constructor(readonly substance: ChemicalSubstanceBean) {
12+
}
13+
}
1314
14-
export class Remove {
15-
static readonly type = `${PREFIX} Remove item`;
15+
export class Remove {
16+
static readonly type = `${PREFIX} Remove item`;
1617
17-
constructor(readonly substanceId: number) {
18-
}
19-
}
18+
constructor(readonly substanceId: number) {
19+
}
20+
}
2021
21-
export class Init {
22-
static readonly type = `${PREFIX} Init items`;
22+
export class Init {
23+
static readonly type = `${PREFIX} Init items`;
2324
24-
constructor(readonly substances: ChemicalSubstanceBean[]) {
25-
}
26-
}
27-
}
25+
constructor(readonly substances: ChemicalSubstanceBean[]) {
26+
}
27+
}
28+
}
29+
**/
Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1-
import {Injectable} from '@angular/core';
2-
import {Action, Selector, State, StateContext, StateToken} from '@ngxs/store';
3-
import {ChemicalSubstanceBean} from '../../obj/bean/ChemicalSubstanceBean';
4-
import {SubstanceAction} from './substance.actions';
1+
/**
2+
import {Injectable} from '@angular/core';
3+
import {Action, Selector, State, StateContext, StateToken} from '@ngxs/store';
4+
import {ChemicalSubstanceBean} from '../../obj/bean/ChemicalSubstanceBean';
5+
import {SubstanceAction} from './substance.actions';
56
6-
export interface SubstanceModel {
7-
substances: ChemicalSubstanceBean[];
8-
}
7+
export interface SubstanceModel {
8+
substances: ChemicalSubstanceBean[];
9+
}
910
10-
const DEFAULTS: SubstanceModel = {
11-
substances: []
12-
}
11+
const DEFAULTS: SubstanceModel = {
12+
substances: []
13+
}
1314
14-
const SUBSTANCE_TOKEN = new StateToken<SubstanceModel>('substance');
15+
const SUBSTANCE_TOKEN = new StateToken<SubstanceModel>('substance');
1516
16-
@State<SubstanceModel>({
17+
@State<SubstanceModel>({
1718
name: SUBSTANCE_TOKEN,
1819
defaults: DEFAULTS
19-
})
20-
@Injectable()
21-
export class SubstanceState {
20+
})
21+
@Injectable()
22+
export class SubstanceState {
2223
23-
@Selector()
24+
@Selector()
2425
static getSubstances(state: SubstanceModel) {
25-
return state.substances;
26+
return state.substances;
2627
}
2728
28-
@Action(SubstanceAction.Add)
29+
@Action(SubstanceAction.Add)
2930
addSubstance(ctx: StateContext<SubstanceModel>, action: SubstanceAction.Add) {
30-
const state = ctx.getState();
31-
ctx.setState({
32-
substances: [...state.substances, action.substance],
33-
});
31+
const state = ctx.getState();
32+
ctx.setState({
33+
substances: [...state.substances, action.substance],
34+
});
3435
}
3536
36-
@Action(SubstanceAction.Remove)
37+
@Action(SubstanceAction.Remove)
3738
removeSubstance(ctx: StateContext<SubstanceModel>, action: SubstanceAction.Remove) {
38-
const state = ctx.getState();
39-
ctx.setState({
40-
substances: state.substances.filter(substance => Number(substance.id) !== action.substanceId),
41-
});
39+
const state = ctx.getState();
40+
ctx.setState({
41+
substances: state.substances.filter(substance => Number(substance.id) !== action.substanceId),
42+
});
4243
}
4344
44-
@Action(SubstanceAction.Init)
45+
@Action(SubstanceAction.Init)
4546
initSubstances(ctx: StateContext<SubstanceModel>, action: SubstanceAction.Init) {
46-
ctx.setState({
47-
substances: action.substances,
48-
});
47+
ctx.setState({
48+
substances: action.substances,
49+
});
4950
}
50-
}
51+
}
52+
**/

0 commit comments

Comments
 (0)