Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pedrofurtado/redux
My own Redux. Just for fun.
https://github.com/pedrofurtado/redux
ecmascript javascript just-for-fun redux redux-clone
Last synced: about 2 months ago
JSON representation
My own Redux. Just for fun.
- Host: GitHub
- URL: https://github.com/pedrofurtado/redux
- Owner: pedrofurtado
- License: mit
- Created: 2018-08-13T15:58:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-07T20:25:20.000Z (over 6 years ago)
- Last Synced: 2024-12-02T06:08:48.445Z (2 months ago)
- Topics: ecmascript, javascript, just-for-fun, redux, redux-clone
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@pedrofurtado/redux
- Size: 427 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Redux
My own Redux. Just for fun.
## Usage
```javascript
import { createStore } from '@pedrofurtado/redux'const reducer1 = (state = [], action) => {
switch(action.type) {
case 'SOME_ACTION':
return [...state, action.payload]
case 'ANOTHER_ACTION':
return [...state, action.another_payload]
case 'LAST_ACTION':
return []
default:
return state
}
}const reducer2 = (state = 5, action) => {
switch(action.type) {
case 'UNIQUE_ACTION':
return 9
default:
return state
}
}const middleware1 = (state, action) => {
console.log('Middleware 1 executing!')
console.log('State at this moment', state)
console.log('Action at this moment', action)
console.log('Middleware 1 executed!')
}const middleware2 = (state, action) => {
console.log('Middleware 2 executing!')
console.log('State at this moment', state)
console.log('Action at this moment', action)
console.log('Middleware 2 executed!')
}const store = createStore(
{
key1: reducer1,
key2: reducer2
},
[
middleware1,
middleware2
]
)store.subscribe(() => {
console.log('Changes detected in state!')
});store.dispatch({ type: 'SOME_ACTION', payload: 'SOMETHING' })
store.dispatch({ type: 'ANOTHER_ACTION', another_payload: 'ANOTHER_THING' })
store.dispatch({ type: 'ACTION_THAT_NOT_EXISTS' })
store.dispatch({ type: 'UNIQUE_ACTION' })
```## Build
To build the `dist/` folder, execute the following command:
```bash
$ docker-compose up --build -d
```or
```bash
$ docker container run --rm -it -v $(pwd):/srv -w /srv node:10 /bin/bash
$ npm install
$ npm run build
```Enjoy!