Skip to content

Commit c7d04c5

Browse files
committed
adding redux;
�����
1 parent 4f067da commit c7d04c5

10 files changed

Lines changed: 112 additions & 17 deletions

File tree

gui/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"npm-run-all": "^4.1.3",
88
"react": "^16.6.0",
99
"react-dom": "^16.6.0",
10-
"react-scripts-ts": "3.1.0"
10+
"react-redux": "^5.1.0",
11+
"react-scripts-ts": "3.1.0",
12+
"redux": "^4.0.1"
1113
},
1214
"scripts": {
1315
"all": "npx run-p watch start:client start:server",
@@ -23,6 +25,7 @@
2325
"@types/node": "^10.12.2",
2426
"@types/react": "^16.4.18",
2527
"@types/react-dom": "^16.0.9",
28+
"@types/redux": "^3.6.0",
2629
"nodemon": "^1.18.6",
2730
"typescript": "^3.1.6"
2831
},

gui/src/actions/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ADD_IMAGE, ImageProperties } from '../constants';
2+
3+
export const addImage = (image: ImageProperties) => (
4+
{ type: ADD_IMAGE, payload: image }
5+
);

gui/src/components/ImageViewer.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import * as React from 'react';
2-
// import { Image } from 'reactstrap';
3-
// import { Image } from 'react-dom'
42
import './ImageViewer.css';
53

6-
export interface Props {
7-
url: string;
8-
alt?: string;
9-
width: number;
10-
height: number
11-
}
4+
import { ImageProperties } from '../constants';
5+
6+
// export interface Props {
7+
// url: string;
8+
// alt?: string;
9+
// width: number;
10+
// height: number
11+
// }
1212

13-
export const ImageViewer = (props: Props) => {
13+
export const ImageViewer = (props: ImageProperties) => {
1414
const img = new Image(props.height, props.width);
1515
img.src = props.url;
1616

@@ -22,4 +22,3 @@ export const ImageViewer = (props: Props) => {
2222
)
2323
}
2424

25-

gui/src/constants/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Action } from 'redux';
2+
export const ADD_IMAGE = "ADD_IMAGE";
3+
4+
// export declare interface Actions {
5+
// type:string;
6+
// }
7+
8+
export interface ImageProperties {
9+
url: string;
10+
alt?: string;
11+
width: number;
12+
height: number
13+
}
14+
15+
export interface ActionWithPayload<T> extends Action {
16+
payload: T;
17+
}

gui/src/reducers/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ActionWithPayload, ADD_IMAGE, ImageProperties, } from '../constants';
2+
3+
4+
const initialState = {
5+
images : Array<ImageProperties>()
6+
};
7+
const rootReducer = (state = initialState, action: ActionWithPayload<ImageProperties> ) => {
8+
switch (action.type){
9+
case ADD_IMAGE:
10+
state.images.push(action.payload);
11+
return state;
12+
default:
13+
return state;
14+
}
15+
};
16+
17+
export default rootReducer;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { get, getAll } from './metadataService';
2+
3+
it('get an object back from ALL call', () => {
4+
const rv = getAll();
5+
expect(typeof rv).toBe('object');
6+
});
7+
8+
it('get single item back', () => {
9+
const rv = get('1234');
10+
expect(rv).toBeInstanceOf(Object);
11+
expect(rv).toMatchObject( { "id": "1234" });
12+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export const getAll = () =>{
3+
return { "metadata": "foobar"};
4+
}
5+
6+
export const get = (id: string) =>{
7+
return { "id": "1234"};
8+
}

gui/src/store/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createStore } from "redux";
2+
import rootReducer from "../reducers/index";
3+
const store = createStore(rootReducer);
4+
export default store;

gui/tslint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"exclude": [
55
"config/**/*.js",
66
"node_modules/**/*.ts",
7-
"coverage/lcov-report/*.js"
7+
"coverage/lcov-report/*.js",
8+
"server/**/*.js",
9+
"server/**/www"
810
]
911
},
1012
"rules": {

gui/yarn.lock

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@
115115
"@types/prop-types" "*"
116116
csstype "^2.2.0"
117117

118+
"@types/redux@^3.6.0":
119+
version "3.6.0"
120+
resolved "https://registry.yarnpkg.com/@types/redux/-/redux-3.6.0.tgz#f1ebe1e5411518072e4fdfca5c76e16e74c1399a"
121+
integrity sha1-8evh5UEVGAcuT9/KXHbhbnTBOZo=
122+
dependencies:
123+
redux "*"
124+
118125
abab@^1.0.3:
119126
version "1.0.4"
120127
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
@@ -4015,7 +4022,7 @@ interpret@^1.0.0:
40154022
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
40164023
integrity sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=
40174024

4018-
invariant@^2.2.2:
4025+
invariant@^2.2.2, invariant@^2.2.4:
40194026
version "2.2.4"
40204027
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
40214028
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
@@ -6757,7 +6764,7 @@ promise@^7.1.1:
67576764
dependencies:
67586765
asap "~2.0.3"
67596766

6760-
prop-types@^15.6.0, prop-types@^15.6.2:
6767+
prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
67616768
version "15.6.2"
67626769
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
67636770
integrity sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==
@@ -6983,16 +6990,29 @@ react-event-listener@^0.6.2:
69836990
prop-types "^15.6.0"
69846991
warning "^4.0.1"
69856992

6986-
react-is@^16.3.2:
6993+
react-is@^16.3.2, react-is@^16.6.0:
69876994
version "16.6.0"
69886995
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.6.0.tgz#456645144581a6e99f6816ae2bd24ee94bdd0c01"
69896996
integrity sha512-q8U7k0Fi7oxF1HvQgyBjPwDXeMplEsArnKt2iYhuIF86+GBbgLHdAmokL3XUFjTd7Q363OSNG55FOGUdONVn1g==
69906997

6991-
react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4:
6998+
react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4:
69926999
version "3.0.4"
69937000
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
69947001
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
69957002

7003+
react-redux@^5.1.0:
7004+
version "5.1.0"
7005+
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.1.0.tgz#948b1e2686473d1999092bcfb32d0dc43d33f667"
7006+
integrity sha512-CRMpEx8+ccpoVxQrQDkG1obExNYpj6dZ1Ni7lUNFB9wcxOhy02tIqpFo4IUXc0kYvCGMu6ABj9A4imEX2VGZJQ==
7007+
dependencies:
7008+
"@babel/runtime" "^7.1.2"
7009+
hoist-non-react-statics "^3.0.0"
7010+
invariant "^2.2.4"
7011+
loose-envify "^1.1.0"
7012+
prop-types "^15.6.1"
7013+
react-is "^16.6.0"
7014+
react-lifecycles-compat "^3.0.0"
7015+
69967016
69977017
version "3.1.0"
69987018
resolved "https://registry.yarnpkg.com/react-scripts-ts/-/react-scripts-ts-3.1.0.tgz#3f285c54b242ff6ecbfb91785060db10660ee7b0"
@@ -7176,6 +7196,14 @@ reduce-function-call@^1.0.1:
71767196
dependencies:
71777197
balanced-match "^0.4.2"
71787198

7199+
redux@*, redux@^4.0.1:
7200+
version "4.0.1"
7201+
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.1.tgz#436cae6cc40fbe4727689d7c8fae44808f1bfef5"
7202+
integrity sha512-R7bAtSkk7nY6O/OYMVR9RiBI+XghjF9rlbl5806HJbQph0LJVHZrU5oaO4q70eUKiqMRqm4y07KLTlMZ2BlVmg==
7203+
dependencies:
7204+
loose-envify "^1.4.0"
7205+
symbol-observable "^1.2.0"
7206+
71797207
regenerate@^1.2.1:
71807208
version "1.4.0"
71817209
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
@@ -8135,7 +8163,7 @@ [email protected]:
81358163
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d"
81368164
integrity sha1-Kb9hXUqnEhvdiYsi1LP5vE4qoD0=
81378165

8138-
symbol-observable@^1.0.4, symbol-observable@^1.1.0:
8166+
symbol-observable@^1.0.4, symbol-observable@^1.1.0, symbol-observable@^1.2.0:
81398167
version "1.2.0"
81408168
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
81418169
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==

0 commit comments

Comments
 (0)