diff --git a/18 Normalizr/src/model/normalized/countryNormalized.ts b/18 Normalizr/src/model/normalized/countryNormalized.ts new file mode 100644 index 0000000..fc87532 --- /dev/null +++ b/18 Normalizr/src/model/normalized/countryNormalized.ts @@ -0,0 +1,4 @@ +export interface CountryNormalized { + id: number; + name: string; +} diff --git a/18 Normalizr/src/model/normalized/studentNormalized.ts b/18 Normalizr/src/model/normalized/studentNormalized.ts new file mode 100644 index 0000000..0f9de98 --- /dev/null +++ b/18 Normalizr/src/model/normalized/studentNormalized.ts @@ -0,0 +1,7 @@ +export interface StudentNormalized { + id: number; + gotActiveTraining: boolean; + fullname: string; + email: string; + country: number; +} diff --git a/18 Normalizr/src/reducers/domain/country/byId.ts b/18 Normalizr/src/reducers/domain/country/byId.ts index 122ef36..5c5d93f 100644 --- a/18 Normalizr/src/reducers/domain/country/byId.ts +++ b/18 Normalizr/src/reducers/domain/country/byId.ts @@ -1,6 +1,6 @@ -import { CountryView } from '../../../model/view/countryView'; +import { CountryNormalized } from '../../../model/normalized/countryNormalized'; -export const byId = (state: {[id: number]: CountryView} = {}, action) => { +export const byId = (state: {[id: number]: CountryNormalized} = {}, action) => { if (action.payload && action.payload.entities) { return { ...state, diff --git a/18 Normalizr/src/reducers/domain/country/index.ts b/18 Normalizr/src/reducers/domain/country/index.ts index d1d0a89..f5859b2 100644 --- a/18 Normalizr/src/reducers/domain/country/index.ts +++ b/18 Normalizr/src/reducers/domain/country/index.ts @@ -1,10 +1,10 @@ import { combineReducers } from 'redux'; import {byId} from './byId'; import {allIds} from './list'; -import { CountryView } from '../../../model/view/countryView'; +import { CountryNormalized } from '../../../model/normalized/countryNormalized'; export interface CountryDomain { - byId: {[id: number]: CountryView}; + byId: {[id: number]: CountryNormalized}; allIds: number[]; } diff --git a/18 Normalizr/src/reducers/domain/country/selectors/index.ts b/18 Normalizr/src/reducers/domain/country/selectors/index.ts index efbc265..4d57a67 100644 --- a/18 Normalizr/src/reducers/domain/country/selectors/index.ts +++ b/18 Normalizr/src/reducers/domain/country/selectors/index.ts @@ -1,6 +1,7 @@ import {createSelector} from 'reselect'; import {State} from '../../../index'; import {CountryDomain} from '../index'; +import {CountryView} from '../../../../model/view/countryView'; export const countryDomain = (state: State) => state.countryDomain; @@ -9,6 +10,6 @@ export const getCountries = createSelector( (state: CountryDomain) => state.allIds.map(id => getCountry(state, id)) ); -export const getCountry = (state: CountryDomain, id) => ({ +export const getCountry = (state: CountryDomain, id: number): CountryView => ({ ...state.byId[id] }); diff --git a/18 Normalizr/src/reducers/domain/student/byId.ts b/18 Normalizr/src/reducers/domain/student/byId.ts index 2e15ca3..b1e8957 100644 --- a/18 Normalizr/src/reducers/domain/student/byId.ts +++ b/18 Normalizr/src/reducers/domain/student/byId.ts @@ -1,6 +1,6 @@ -import { StudentView } from "../../../model/view/studentView"; +import { StudentNormalized } from "../../../model/normalized/studentNormalized"; -export const byId = (state : {[id: number] : StudentView} = {}, action) => { +export const byId = (state : {[id: number] : StudentNormalized} = {}, action) => { if (action.payload && action.payload.entities) { return { ...state, diff --git a/18 Normalizr/src/reducers/domain/student/index.ts b/18 Normalizr/src/reducers/domain/student/index.ts index dbedc3e..da74a67 100644 --- a/18 Normalizr/src/reducers/domain/student/index.ts +++ b/18 Normalizr/src/reducers/domain/student/index.ts @@ -2,10 +2,10 @@ import { combineReducers } from 'redux'; import {byId} from './byId'; import {allIds} from './list'; import { edit, EditState } from './edit'; -import { StudentView } from '../../../model/view/studentView'; +import { StudentNormalized } from '../../../model/normalized/studentNormalized'; export interface StudentDomain { - byId: {[id: number] : StudentView}, + byId: {[id: number] : StudentNormalized}, allIds: number[]; edit: EditState; }; diff --git a/18 Normalizr/src/reducers/domain/student/selectors/index.ts b/18 Normalizr/src/reducers/domain/student/selectors/index.ts index a7a3329..0d711f3 100644 --- a/18 Normalizr/src/reducers/domain/student/selectors/index.ts +++ b/18 Normalizr/src/reducers/domain/student/selectors/index.ts @@ -14,7 +14,7 @@ export const getStudents = createSelector( studentDomain.allIds.map(id => getStudent(studentDomain, countryDomain, id)) ); -const getStudent = (studentDomain: StudentDomain, countryDomain: CountryDomain, id): StudentView => ({ +const getStudent = (studentDomain: StudentDomain, countryDomain: CountryDomain, id: number): StudentView => ({ ...studentDomain.byId[id], country: getCountry(countryDomain, studentDomain.byId[id].country) });