Skip to content

A small state management library inspired from ngrx api

License

Notifications You must be signed in to change notification settings

vincent/not-ngrx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

not-ngrx

A small state management library inspired from ngrx api

install

npm install not-ngrx

usage

import { Store, Action } from "not-ngrx";

// A state interface
interface State {
    feature: {
        prop: string;
    }
}

// An initial state
const initialState = {
    feature: {
        prop: 'initial'
    }
};

// A reducer
const reducer = (state: State, action: Action): State => {
  switch (action.type) {
      case 'MY_ACTION_TYPE':
        return {
            ...state,
            feature: { ...state.feature, prop: 'modified' }
        };
    default:
        return state;
  }
};

// The store
const store = new Store<State>(initialState, [ reducer ]);

// Dispatch an action
store.dispatch({ type: 'MY_ACTION_TYPE' });

// Listen to root state changes
store.subscribe(root => {
    console.log(root);
});

// Listen to state changes on a specific slice
store.select('feature.prop').subscribe(slice => {
    console.log(slice);
});

About

A small state management library inspired from ngrx api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published