Skip to content

Commit

Permalink
feat(app-config): add redux and saga configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Dec 24, 2020
1 parent 7d070cb commit 2db5d13
Show file tree
Hide file tree
Showing 8 changed files with 2,946 additions and 767 deletions.
3,562 changes: 2,826 additions & 736 deletions packages/game-app/package-lock.json

Large diffs are not rendered by default.

27 changes: 16 additions & 11 deletions packages/game-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",
"@types/jest": "^26.0.19",
"@types/node": "^12.19.9",
"@types/react": "^16.14.2",
"@types/react-dom": "^16.9.10",
"env-cmd": "^10.1.0",
"@reduxjs/toolkit": "^1.5.0",
"firebase": "^8.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"typescript": "^4.1.3",
"react-redux": "^7.2.2",
"redux-saga": "^1.1.3",
"web-vitals": "^0.2.4"
},
"scripts": {
Expand Down Expand Up @@ -50,8 +43,20 @@
"devDependencies": {
"@cypress/code-coverage": "^3.8.8",
"@cypress/instrument-cra": "^1.4.0",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",
"@types/jest": "^26.0.19",
"@types/node": "^12.19.9",
"@types/react": "^16.14.2",
"@types/react-dom": "^16.9.10",
"@types/react-redux": "^7.1.14",
"@types/redux-saga": "^0.10.5",
"cypress": "^6.2.0",
"env-cmd": "^10.1.0",
"react-app-rewire-alias": "^0.1.9",
"react-app-rewired": "^2.1.8"
"react-app-rewired": "^2.1.8",
"react-scripts": "4.0.1",
"typescript": "^4.1.3"
}
}
31 changes: 31 additions & 0 deletions packages/game-app/src/_shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {buildStore} from "./store";
import firebase from "firebase";
import CONFIG from "@pipeline/app-config";
import 'firebase/analytics';
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/database';

export function bootstrap() {

firebase.initializeApp({
apiKey: CONFIG.REACT_APP_FIREBASE_CONFIG_API_KEY,
authDomain: CONFIG.REACT_APP_FIREBASE_CONFIG_AUTH_DOMAIN,
databaseURL: CONFIG.REACT_APP_FIREBASE_CONFIG_DATABASE_URL,
projectId: CONFIG.REACT_APP_FIREBASE_CONFIG_PROJECT_ID,
storageBucket: CONFIG.REACT_APP_FIREBASE_CONFIG_STORAGE_BUCKET,
messagingSenderId: CONFIG.REACT_APP_FIREBASE_CONFIG_MESSAGING_SENDER_ID,
appId: CONFIG.REACT_APP_FIREBASE_CONFIG_APP_ID,
});

firebase.analytics();

const store = buildStore();

store.dispatch({type: 'test'});
// For sage test
store.dispatch({type: 'ping'});

return store;

}
18 changes: 18 additions & 0 deletions packages/game-app/src/_shared/store/buildStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {configureStore} from '@reduxjs/toolkit';
import createSagaMiddleware from 'redux-saga';
import reducers from "./reducers";
import rootSaga from "./rootSaga";

const sagaMiddleware = createSagaMiddleware();

export default function () {
const store = configureStore({
reducer: reducers,
middleware: [
sagaMiddleware
]
});

sagaMiddleware.run(rootSaga)
return store;
}
7 changes: 7 additions & 0 deletions packages/game-app/src/_shared/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


import buildStore from "./buildStore";

export {
buildStore
}
11 changes: 11 additions & 0 deletions packages/game-app/src/_shared/store/reducers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Action, ReducersMapObject} from "@reduxjs/toolkit";

function testReducer(state = {}, action: Action) {
return state;
}

const reducers: ReducersMapObject = {
test: testReducer
};

export default reducers;
31 changes: 31 additions & 0 deletions packages/game-app/src/_shared/store/rootSaga.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {Saga} from 'redux-saga';
import {all, call, put, spawn, takeEvery} from 'redux-saga/effects'

function* testSaga() {
yield put({type: 'pong'});
}

function * testSagaRunner(){
yield takeEvery('ping', testSaga);
}

export default function* rootSaga() {
const sagas: Saga[] = [
testSagaRunner
];

yield all(
sagas.map(saga =>
spawn(function* () {
while (true) {
try {
yield call(saga);
break;
} catch (e) {
console.log(e);
}
}
}),
),
);
}
26 changes: 6 additions & 20 deletions packages/game-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,16 @@ import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

import firebase from 'firebase/app';
import {bootstrap} from "./_shared";
import {Provider} from "react-redux";

import 'firebase/analytics';
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/database';

import CONFIG from '@pipeline/app-config'

firebase.initializeApp({
apiKey: CONFIG.REACT_APP_FIREBASE_CONFIG_API_KEY,
authDomain: CONFIG.REACT_APP_FIREBASE_CONFIG_AUTH_DOMAIN,
databaseURL: CONFIG.REACT_APP_FIREBASE_CONFIG_DATABASE_URL,
projectId: CONFIG.REACT_APP_FIREBASE_CONFIG_PROJECT_ID,
storageBucket: CONFIG.REACT_APP_FIREBASE_CONFIG_STORAGE_BUCKET,
messagingSenderId: CONFIG.REACT_APP_FIREBASE_CONFIG_MESSAGING_SENDER_ID,
appId: CONFIG.REACT_APP_FIREBASE_CONFIG_APP_ID,
});

firebase.analytics();
const store = bootstrap();

ReactDOM.render(
<React.StrictMode>
<App />
<Provider store={store}>
<App/>
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
Expand Down

0 comments on commit 2db5d13

Please sign in to comment.