Commit a4f628c6 authored by Lavitr's avatar Lavitr

simple Redux action implemented

parent 386f4123
...@@ -198,8 +198,7 @@ ...@@ -198,8 +198,7 @@
"asap": { "asap": {
"version": "2.0.6", "version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=", "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
"dev": true
}, },
"asn1": { "asn1": {
"version": "0.2.3", "version": "0.2.3",
...@@ -2626,6 +2625,12 @@ ...@@ -2626,6 +2625,12 @@
"mimic-response": "1.0.0" "mimic-response": "1.0.0"
} }
}, },
"deep-diff": {
"version": "0.3.8",
"resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-0.3.8.tgz",
"integrity": "sha1-wB3mPvsO7JeYgB1Ax+Da4ltYLIQ=",
"dev": true
},
"deep-equal": { "deep-equal": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
...@@ -2930,7 +2935,6 @@ ...@@ -2930,7 +2935,6 @@
"version": "0.1.12", "version": "0.1.12",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
"dev": true,
"requires": { "requires": {
"iconv-lite": "0.4.19" "iconv-lite": "0.4.19"
} }
...@@ -3484,7 +3488,6 @@ ...@@ -3484,7 +3488,6 @@
"version": "0.8.16", "version": "0.8.16",
"resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.16.tgz", "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.16.tgz",
"integrity": "sha1-XmdDL1UNxBtXK/VYR7ispk5TN9s=", "integrity": "sha1-XmdDL1UNxBtXK/VYR7ispk5TN9s=",
"dev": true,
"requires": { "requires": {
"core-js": "1.2.7", "core-js": "1.2.7",
"isomorphic-fetch": "2.2.1", "isomorphic-fetch": "2.2.1",
...@@ -3498,8 +3501,7 @@ ...@@ -3498,8 +3501,7 @@
"core-js": { "core-js": {
"version": "1.2.7", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=", "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY="
"dev": true
} }
} }
}, },
...@@ -5098,6 +5100,11 @@ ...@@ -5098,6 +5100,11 @@
"integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=", "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=",
"dev": true "dev": true
}, },
"hoist-non-react-statics": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz",
"integrity": "sha512-6Bl6XsDT1ntE0lHbIhr4Kp2PGcleGZ66qu5Jqk8lc0Xc/IeG6gVLmwUGs/K0Us+L8VWoKgj0uWdPMataOsm31w=="
},
"home-or-tmp": { "home-or-tmp": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz", "resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz",
...@@ -5472,8 +5479,7 @@ ...@@ -5472,8 +5479,7 @@
"iconv-lite": { "iconv-lite": {
"version": "0.4.19", "version": "0.4.19",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
"integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==", "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ=="
"dev": true
}, },
"icss-replace-symbols": { "icss-replace-symbols": {
"version": "1.1.0", "version": "1.1.0",
...@@ -5630,7 +5636,6 @@ ...@@ -5630,7 +5636,6 @@
"version": "2.2.3", "version": "2.2.3",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.3.tgz", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.3.tgz",
"integrity": "sha512-7Z5PPegwDTyjbaeCnV0efcyS6vdKAU51kpEmS7QFib3P4822l8ICYyMn7qvJnc+WzLoDsuI9gPMKbJ8pCu8XtA==", "integrity": "sha512-7Z5PPegwDTyjbaeCnV0efcyS6vdKAU51kpEmS7QFib3P4822l8ICYyMn7qvJnc+WzLoDsuI9gPMKbJ8pCu8XtA==",
"dev": true,
"requires": { "requires": {
"loose-envify": "1.3.1" "loose-envify": "1.3.1"
} }
...@@ -5925,8 +5930,7 @@ ...@@ -5925,8 +5930,7 @@
"is-stream": { "is-stream": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
"dev": true
}, },
"is-svg": { "is-svg": {
"version": "2.1.0", "version": "2.1.0",
...@@ -5989,7 +5993,6 @@ ...@@ -5989,7 +5993,6 @@
"version": "2.2.1", "version": "2.2.1",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz",
"integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=",
"dev": true,
"requires": { "requires": {
"node-fetch": "1.7.3", "node-fetch": "1.7.3",
"whatwg-fetch": "2.0.3" "whatwg-fetch": "2.0.3"
...@@ -6031,8 +6034,7 @@ ...@@ -6031,8 +6034,7 @@
"js-tokens": { "js-tokens": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
"integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls="
"dev": true
}, },
"js-yaml": { "js-yaml": {
"version": "3.7.0", "version": "3.7.0",
...@@ -6622,8 +6624,12 @@ ...@@ -6622,8 +6624,12 @@
"lodash": { "lodash": {
"version": "4.17.5", "version": "4.17.5",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==", "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="
"dev": true },
"lodash-es": {
"version": "4.17.8",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.8.tgz",
"integrity": "sha512-I9mjAxengFAleSThFhhAhvba6fsO0hunb9/0sQ6qQihSZsJRBofv2rYH58WXaOb/O++eUmYpCLywSQ22GfU+sA=="
}, },
"lodash.camelcase": { "lodash.camelcase": {
"version": "4.3.0", "version": "4.3.0",
...@@ -6711,7 +6717,6 @@ ...@@ -6711,7 +6717,6 @@
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz",
"integrity": "sha1-0aitM/qc4OcT1l/dCsi3SNR4yEg=", "integrity": "sha1-0aitM/qc4OcT1l/dCsi3SNR4yEg=",
"dev": true,
"requires": { "requires": {
"js-tokens": "3.0.2" "js-tokens": "3.0.2"
} }
...@@ -7292,7 +7297,6 @@ ...@@ -7292,7 +7297,6 @@
"version": "1.7.3", "version": "1.7.3",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
"dev": true,
"requires": { "requires": {
"encoding": "0.1.12", "encoding": "0.1.12",
"is-stream": "1.1.0" "is-stream": "1.1.0"
...@@ -7447,8 +7451,7 @@ ...@@ -7447,8 +7451,7 @@
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
"dev": true
}, },
"object-copy": { "object-copy": {
"version": "0.1.0", "version": "0.1.0",
...@@ -8626,7 +8629,6 @@ ...@@ -8626,7 +8629,6 @@
"version": "7.3.1", "version": "7.3.1",
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
"integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
"dev": true,
"requires": { "requires": {
"asap": "2.0.6" "asap": "2.0.6"
} }
...@@ -8641,7 +8643,6 @@ ...@@ -8641,7 +8643,6 @@
"version": "15.6.1", "version": "15.6.1",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.1.tgz", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.1.tgz",
"integrity": "sha512-4ec7bY1Y66LymSUOH/zARVYObB23AT2h8cf6e/O6ZALB/N0sqZFEx7rq6EYPX2MkOdKORuooI/H5k9TlR4q7kQ==", "integrity": "sha512-4ec7bY1Y66LymSUOH/zARVYObB23AT2h8cf6e/O6ZALB/N0sqZFEx7rq6EYPX2MkOdKORuooI/H5k9TlR4q7kQ==",
"dev": true,
"requires": { "requires": {
"fbjs": "0.8.16", "fbjs": "0.8.16",
"loose-envify": "1.3.1", "loose-envify": "1.3.1",
...@@ -8833,6 +8834,19 @@ ...@@ -8833,6 +8834,19 @@
"prop-types": "15.6.1" "prop-types": "15.6.1"
} }
}, },
"react-redux": {
"version": "5.0.7",
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-5.0.7.tgz",
"integrity": "sha512-5VI8EV5hdgNgyjfmWzBbdrqUkrVRKlyTKk1sGH3jzM2M2Mhj/seQgPXaz6gVAj2lz/nz688AdTqMO18Lr24Zhg==",
"requires": {
"hoist-non-react-statics": "2.5.0",
"invariant": "2.2.3",
"lodash": "4.17.5",
"lodash-es": "4.17.8",
"loose-envify": "1.3.1",
"prop-types": "15.6.1"
}
},
"read-chunk": { "read-chunk": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-2.1.0.tgz", "resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-2.1.0.tgz",
...@@ -8972,6 +8986,38 @@ ...@@ -8972,6 +8986,38 @@
} }
} }
}, },
"redux": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/redux/-/redux-3.7.2.tgz",
"integrity": "sha512-pNqnf9q1hI5HHZRBkj3bAngGZW/JMCmexDlOxw4XagXY2o1327nHH54LoTjiPJ0gizoqPDRqWyX/00g0hD6w+A==",
"requires": {
"lodash": "4.17.5",
"lodash-es": "4.17.8",
"loose-envify": "1.3.1",
"symbol-observable": "1.2.0"
},
"dependencies": {
"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=="
}
}
},
"redux-logger": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/redux-logger/-/redux-logger-3.0.6.tgz",
"integrity": "sha1-91VZZvMJjzyIYExEnPC69XeCdL8=",
"dev": true,
"requires": {
"deep-diff": "0.3.8"
}
},
"redux-thunk": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.2.0.tgz",
"integrity": "sha1-5hWhbha0ehmlFXZhM9Hj6Zt4UuU="
},
"regenerate": { "regenerate": {
"version": "1.3.3", "version": "1.3.3",
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz",
...@@ -9454,8 +9500,7 @@ ...@@ -9454,8 +9500,7 @@
"setimmediate": { "setimmediate": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=", "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
"dev": true
}, },
"setprototypeof": { "setprototypeof": {
"version": "1.1.0", "version": "1.1.0",
...@@ -10334,8 +10379,7 @@ ...@@ -10334,8 +10379,7 @@
"ua-parser-js": { "ua-parser-js": {
"version": "0.7.17", "version": "0.7.17",
"resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz", "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz",
"integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g==", "integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g=="
"dev": true
}, },
"uglify-es": { "uglify-es": {
"version": "3.3.9", "version": "3.3.9",
...@@ -11047,8 +11091,7 @@ ...@@ -11047,8 +11091,7 @@
"whatwg-fetch": { "whatwg-fetch": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz",
"integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=", "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ="
"dev": true
}, },
"whet.extend": { "whet.extend": {
"version": "0.9.9", "version": "0.9.9",
......
...@@ -22,9 +22,15 @@ ...@@ -22,9 +22,15 @@
"html-webpack-plugin": "^3.0.6", "html-webpack-plugin": "^3.0.6",
"react": "^16.2.0", "react": "^16.2.0",
"react-dom": "^16.2.0", "react-dom": "^16.2.0",
"redux-logger": "^3.0.6",
"style-loader": "^0.20.3", "style-loader": "^0.20.3",
"webpack": "^4.1.1", "webpack": "^4.1.1",
"webpack-cli": "^2.0.10", "webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.1" "webpack-dev-server": "^3.1.1"
},
"dependencies": {
"react-redux": "^5.0.7",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
} }
} }
Action creators are exactly that—functions that create actions. It's easy to conflate the terms “action” and “action creator”, so do your best to use the proper term.
In Redux, action creators simply return an action:
. Remember that actions only describe the fact that something happened, but don't describe how the application's state changes.
Reducers specify how the application's state changes in response to actions sent to the store.
Remember that actions only describe the fact that something happened, but don't describe how the application's state changes.
This tutorial is for people who is completely new to Redux and haven't disptched any action yet .
When we start to learn some new programming language or framework the first thing we about to do is to write "Hello world" , in other words to perform some tiny task .So to say "Hello World" in Redux would be equal to
dispatch a simple action . But somehow for me it wasn't an easy task at all .Actually I had spent too much time before I finally succeeded to dispatch first action.My thoughts was kind of "Should I write Action first or Reducer first.
And even if I write action and reducer how my React component supposed to know about both of them and so on. "
\ No newline at end of file
//This file contatins 'ACTION-CREATOR' functions
//In Redux, 'ACTION-CREATOR' return an ACTION(plain JavaScript object)
//example of simple 'ACTION-CREATOR'
export const sayHello = () => ({
type: "HELLO_REACT"
})
import React from 'react' import React from 'react'
import Button from '../containers/Button'
const App = () => ( let App = () => (
<div> <div >
<p>Hello React</p> <Button />
</div> </div>
) )
export default App; export default App;
\ No newline at end of file
import React from 'react'
import { connect } from 'react-redux'
import { sayHello } from '../actions'
let Button = ({ whatsUp, state, saySomething }) => (
<div >
<button onClick={saySomething}>PRESS TO DISPATCH FIRST ACTION</button>
<h2>{whatsUp}</h2>
<button onClick={() => console.log(state)} >Press to inspect STATE in console panel</button>
</div>
)
const mapStateToProps = (state) => ({
whatsUp: state.say,
state: state
})
const mapDispatchToProps = {
saySomething: sayHello
}
Button = connect(
mapStateToProps,
mapDispatchToProps
)(Button)
export default Button;
import React from 'react'
* { * {
box-sizing: border-box; box-sizing: border-box;
} }
body{
background-color: beige;
}
import React from 'react' import React from 'react'
import { render } from 'react-dom' import { render } from 'react-dom'
import App from "./components/App"; import { createStore} from 'redux'
import { Provider } from 'react-redux'
import reducer from './reducers'
import './css/styles.css'
import App from "./components/App"
const store = createStore(reducer)
render( render(
<App/>, <Provider store={store}>
<App />
</Provider>,
document.getElementById('root') document.getElementById('root')
) )
\ No newline at end of file
const reducer = (state = {}, action) => {
switch (action.type) {
case 'HELLO_REACT':
return { ...state, say : 'Hello World Redux' };
default:
return state;
}
};
export default reducer;
\ No newline at end of file
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