1.0.2 • Published 6 years ago
pedrofurtado-redux v1.0.2
Pedro Furtado Redux
My own Redux. Just for fun.
Example usage
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:
$ docker-compose up --build -d
Alert: Don't use it in your projects!
This repo is just for study, in order to understand how Redux works behind the scenes. Naturally, the official Redux is much more flexible and complex. But, for fun, I've made a simple version of it.
Enjoy!