Skip to content

a small implementation of redux to better understand its design patterns

Notifications You must be signed in to change notification settings

paulserraino/mini-redux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

#mini-redux Small implementation of redux to better understand it's design patterns

const createStore = require('./mini-redux').createStore;

function AppReducer(state, action) {
    switch (action.type) {
        case 'inc':
            return state + 1
        default:
            return state
    }
}

var intialState = 0;

var store = createStore(intialState, AppReducer);

var unsubscribe = store.subscribe((state) => {
    console.log(state);
})

store.dispatch({ type: 'init'}) // => 0
store.dispatch({ type: 'foo'}) // => 0
store.dispatch({ type: 'inc'}) // => 1
store.dispatch({ type: 'inc'}) // => 2
store.dispatch({ type: 'bar'}) // => 2

unsubscribe()

License

MIT

About

a small implementation of redux to better understand its design patterns

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published