Skip to content

Small state management like Redux. It's a hobby.

Notifications You must be signed in to change notification settings

hiro08gh/hobby-redux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hobby-redux

Small configuration state management like Redux. It's a hobby.

Usage

import { Store } from './store';

type CounterAction = { type: 'INCREMENT' } | { type: 'DECREMENT' };

const reducer = (state: number = 0, action: CounterAction) => {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1;
    case 'DECREMENT':
      return state - 1;
    default:
      return state;
  }
};

const store = new Store(reducer);

const incrementAction = { type: 'INCREMENT' };
const decrementAction = { type: 'DECREMENT' };

store.subscribe(fn);

function fn() {
  console.log(store.getState());
}

// Add to the numbers + 1
store.dispatch(incrementAction); // => 1
store.dispatch(incrementAction); // => 2

// Subtract numbers -1
store.dispatch(decrementAction);// => 1

test

$ npm run test

build

$ npm run build

Author

@hiro08gh

About

Small state management like Redux. It's a hobby.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published