Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 18 Normalizr/src/model/normalized/countryNormalized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface CountryNormalized {
id: number;
name: string;
}
7 changes: 7 additions & 0 deletions 18 Normalizr/src/model/normalized/studentNormalized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface StudentNormalized {
id: number;
gotActiveTraining: boolean;
fullname: string;
email: string;
country: number;
}
4 changes: 2 additions & 2 deletions 18 Normalizr/src/reducers/domain/country/byId.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions 18 Normalizr/src/reducers/domain/country/index.ts
Original file line number Diff line number Diff line change
@@ -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[];
}

Expand Down
3 changes: 2 additions & 1 deletion 18 Normalizr/src/reducers/domain/country/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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]
});
4 changes: 2 additions & 2 deletions 18 Normalizr/src/reducers/domain/student/byId.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions 18 Normalizr/src/reducers/domain/student/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});