|
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'; |
5 | 6 |
|
6 | | -export interface SubstanceModel { |
7 | | - substances: ChemicalSubstanceEntryBean[]; |
8 | | -} |
| 7 | + export interface SubstanceModel { |
| 8 | + substances: ChemicalSubstanceEntryBean[]; |
| 9 | + } |
9 | 10 |
|
10 | | -const DEFAULTS: SubstanceModel = { |
11 | | - substances: [] |
12 | | -} |
| 11 | + const DEFAULTS: SubstanceModel = { |
| 12 | + substances: [] |
| 13 | + } |
13 | 14 |
|
14 | | -const SUBSTANCE_TOKEN = new StateToken<SubstanceModel>('inventory'); |
| 15 | + const SUBSTANCE_TOKEN = new StateToken<SubstanceModel>('inventory'); |
15 | 16 |
|
16 | | -@State<SubstanceModel>({ |
| 17 | + @State<SubstanceModel>({ |
17 | 18 | name: SUBSTANCE_TOKEN, |
18 | 19 | defaults: DEFAULTS |
19 | | -}) |
20 | | -@Injectable() |
21 | | -export class InventoryState { |
| 20 | + }) |
| 21 | + @Injectable() |
| 22 | + export class InventoryState { |
22 | 23 |
|
23 | | - @Selector() |
| 24 | + @Selector() |
24 | 25 | static getSubstanceEntries(state: SubstanceModel) { |
25 | | - return state.substances; |
| 26 | + return state.substances; |
26 | 27 | } |
27 | 28 |
|
28 | | - @Selector() |
| 29 | + @Selector() |
29 | 30 | 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); |
31 | 32 | } |
32 | 33 |
|
33 | | - @Action(InventoryAction.AddSubstance) |
| 34 | + @Action(InventoryAction.AddSubstance) |
34 | 35 | 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 | + }); |
39 | 40 | } |
40 | 41 |
|
41 | | - @Action(InventoryAction.RemoveSubstance) |
| 42 | + @Action(InventoryAction.RemoveSubstance) |
42 | 43 | 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 | + }); |
47 | 48 | } |
48 | 49 |
|
49 | | - @Action(InventoryAction.InitSubstances) |
| 50 | + @Action(InventoryAction.InitSubstances) |
50 | 51 | initSubstances(ctx: StateContext<SubstanceModel>, action: InventoryAction.InitSubstances) { |
51 | | - ctx.setState({ |
52 | | - substances: action.substances, |
53 | | - }); |
| 52 | + ctx.setState({ |
| 53 | + substances: action.substances, |
| 54 | + }); |
54 | 55 | } |
55 | | -} |
| 56 | + } |
| 57 | +
|
| 58 | + */ |
0 commit comments