redux-store-factory
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

REDUX-STORE-FACTORY

Tools library for building redux store

HOW TO

Install package with command line : npm install redux-store-factory

Next get an instance of your store with :

interface Data {
  A: {
    a1: string;
    a2: string;
  };
}
const initialState: Data = {
  A: {
    a1: "a1",
    a2: "a2",
  },
};

import reduxStoreFactory from "redux-store-factory";
// Make a redux store factory instance
const store = new reduxStoreFactory<Data>(initialState, "myTestStore");

// Obtain your reducer:
const myReducer = store.reducer;

// Obtain your middlware (static) :
const myMiddleware = reduxStoreFactory.middleware;

// Try action creator for dispatcher to update A.a1:
const myActionUpdateToDispatch = store.update.A.a1("My New Value");
// OR
const anOtherActionUpdateToDispatch = store.update.A.resolve({ a1: "My New Value" });

// Try action creator for dispatcher to reset initialState on A.a1:
const myActionResetToDispatch = store.reset.A.a1();
// Try action creator for dispatcher to reset initialState on A:
const anOtherActionResetToDispatch = store.reset.A.resolve();

// Add action for middleware
import { ExecuteAction } from "redux-store-factory";
store.execute.myAction = new ExecuteAction(
  (store: any) => (next: any) => (action: any) => {
    console.log(`I do something cool : ${action.payload} !`);
  }
);

// Get action to dispatch for middleware
const myPayload = "something cool";
const myActionToDispatch = store.execute.myAction.create(myPayload);

Readme

Keywords

Package Sidebar

Install

npm i redux-store-factory

Weekly Downloads

1

Version

1.0.11

License

GPL-3.0

Unpacked Size

51.8 kB

Total Files

15

Last publish

Collaborators

  • jkehl