Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
omprashantjain committed Nov 2, 2023
1 parent 973bcd0 commit 5bfc7b2
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions 52 Redux/1-only-redux/kg-coding-redux.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const redux = require('redux');

const INITIAL_VALUE = {
counter: 0
};

const reducer = (store = INITIAL_VALUE, action) => {
let newStore = store;
if (action.type === 'INCREMENT') {
newStore = {counter: store.counter + 1};
} else if (action.type === 'DECREMENT') {
newStore = {counter: store.counter - 1};
} else if (action.type === 'ADDITION') {
newStore = {counter: store.counter + action.payload.number};
}
return newStore;
}

const store = redux.createStore(reducer);

const subscriber = () => {
const state = store.getState();
console.log(state);
}

store.subscribe(subscriber);

store.dispatch({type: 'INCREMENT'});
store.dispatch({type: 'DECREMENT'});
store.dispatch({type: 'INCREMENT'});
store.dispatch({type: 'ADDITION', payload: {number: 7}});
store.dispatch({type: 'DECREMENT'});
40 changes: 40 additions & 0 deletions 52 Redux/1-only-redux/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions 52 Redux/1-only-redux/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "1-only-redux",
"version": "1.0.0",
"description": "",
"main": "kg-coding-redux.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"redux": "^4.2.1"
}
}

0 comments on commit 5bfc7b2

Please sign in to comment.