forked from Complete-Coding/React_Complete_YouTube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
973bcd0
commit 5bfc7b2
Showing
24 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |