Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.clear()
- const createPolicy = (name, amount) => {
- return {
- type: 'CREATE_POLICY'
- payload: {
- name: name,
- amount: amount
- }
- }
- }
- const deletePolicy = (name) => {
- return {
- type: 'DELETE_POLICY'
- payload: {
- name: name,
- }}
- }
- const createClaim = (name,amountOfMoneyToCollect) => {
- return {
- type: 'CREATE_CLAIM'
- payload: {
- name: name,
- amountOfMoneyToCollect: amountOfMoneyToCollect
- }}
- }
- // Reducers
- const claimsHistory = (oldListOfClaims = [], action) => {
- if (action.type === 'CREATE_CLAIM'){
- return [...oldListOfClaims, action.payload]
- }
- return oldListOfClaims
- }
- const accounting = (bagOfMoney = 1000, action) => {
- if (action.type === 'CREATE_CLAIM') {
- return bagOfMoney - action.payload.amountOfMoneyToCollect
- } else if (action.type === 'CREATE_POLICY'){
- return bagOfMoney + action.payload.amount
- }
- return bagOfMoney
- }
- const policies = (listOfPolicies = [], action){
- if (action.type === 'CREATE_POLICY'){
- return [...listOfPolicies, action.payload.name]
- }
- else if (action.type === 'DELETE_POLICY'){
- return listOfPolicies.filter((name)=>(name!==action.payload.name))
- }
- }
- const {createStore, combineReducers} = Redux
- const ourDepartments = combineReducers({
- accounting,
- claimsHistory,
- policies
- })
- const store = createStore(ourDepartments)
- const action = createPolicy('Alex', 20)
- store.dispatch(action)
- console.log(store.getState())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement