Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tik-tak-toe/node_modules
tik-tak-toe/.DS_Store
react-essentials/node_modules
calculator/node_modules
calculator/node_modules
redux/node_modules
22 changes: 22 additions & 0 deletions redux/package-lock.json

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

16 changes: 16 additions & 0 deletions redux/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "redux",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"dependencies": {
"redux": "^5.0.1"
}
}
29 changes: 29 additions & 0 deletions redux/redux-demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const redux = require("redux");

const counterReducer = (state = { counter: 0 }, action) => {
if (action.type === "increment") {
return {
counter: state.counter + 1,
};
}

if (action.type === "decrement") {
return {
counter: state.counter - 1,
};
}

return state;
};

const store = redux.createStore(counterReducer);

const counterSubscriber = () => {
const latestState = store.getState();
console.log(latestState);
};

store.subscribe(counterSubscriber);

store.dispatch({ type: "increment" });
store.dispatch({ type: "decrement" });