Commit 96d329bc authored by Alexander Kotov's avatar Alexander Kotov

redux: track moves count

parent 86fa8c84
...@@ -8986,6 +8986,15 @@ ...@@ -8986,6 +8986,15 @@
} }
} }
}, },
"redux": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/redux/-/redux-4.0.0.tgz",
"integrity": "sha512-NnnHF0h0WVE/hXyrB6OlX67LYRuaf/rJcbWvnHHEPCF/Xa/AZpwhs/20WyqzQae5x4SD2F9nPObgBh2rxAgLiA==",
"requires": {
"loose-envify": "^1.1.0",
"symbol-observable": "^1.2.0"
}
},
"regenerate": { "regenerate": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz",
...@@ -10002,6 +10011,11 @@ ...@@ -10002,6 +10011,11 @@
"serviceworker-cache-polyfill": "^4.0.0" "serviceworker-cache-polyfill": "^4.0.0"
} }
}, },
"symbol-observable": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz",
"integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ=="
},
"symbol-tree": { "symbol-tree": {
"version": "3.2.2", "version": "3.2.2",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.2.tgz", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.2.tgz",
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
"dependencies": { "dependencies": {
"react": "^16.4.2", "react": "^16.4.2",
"react-dom": "^16.4.2", "react-dom": "^16.4.2",
"react-scripts": "1.1.4" "react-scripts": "1.1.4",
"redux": "^4.0.0"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
...@@ -13,4 +14,4 @@ ...@@ -13,4 +14,4 @@
"test": "react-scripts test --env=jsdom", "test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject" "eject": "react-scripts eject"
} }
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ import './App.css' ...@@ -3,6 +3,8 @@ import './App.css'
import Tower from './components/Tower/Tower.jsx' import Tower from './components/Tower/Tower.jsx'
import Disk from './components/Disk/Disk.jsx'; import Disk from './components/Disk/Disk.jsx';
import store from './store';
import { completeMove } from './actions/moveActions';
const styles = { const styles = {
air: { air: {
...@@ -70,6 +72,8 @@ class App extends Component { ...@@ -70,6 +72,8 @@ class App extends Component {
[move.to]: disks, [move.to]: disks,
move: null move: null
}) })
store.dispatch(completeMove(move))
} }
performMove = tower => () => { performMove = tower => () => {
......
import { COMPLETE_MOVE } from "./types";
export const completeMove = (move) => ({
type: COMPLETE_MOVE,
payload: move
})
export const COMPLETE_MOVE = 'COMPLETE_MOVE'
\ No newline at end of file
import { combineReducers } from "redux"
import moves from './movesReducer'
export default combineReducers({
moves
})
\ No newline at end of file
import { COMPLETE_MOVE } from "../actions/types";
export default (moves = 0, action) => {
switch (action.type) {
case COMPLETE_MOVE:
return moves + 1
default:
return moves
}
}
import { createStore } from 'redux'
import rootReducer from './reducers'
export default createStore(
rootReducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment