0.0.3 • Published 3 years ago

react-redux-mixer v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

react-redux-mixer

a tool to reduce your code, especially your reducers

forget switches and types in your reducers, declare just the name, and the initial state, and follow the event pattern

usage

simpler than any other

  • src/reducers/store.js
    import { createStore, combineReducers } from 'redux';
    import { ReduxMixer } from 'react-redux-mixer';
    import { user } from './reducer';

    const rootReducer = combineReducers({
        user,
        products: ReduxMixer('products', []),
        validations: ReduxMixer('validations', [], 'uuid'),
    });

    const store = createStore(rootReducer);

    export default store;

optional

  • src/typings/root.d.ts

this will make vs intellicode give good suggestions when typing

import { User, Product, Validation } from './models'

  declare module 'react-redux' {
    export interface DefaultRootState {
        user: User,
        products: Product[],
        validations: Validation[],
    }
}

example

standardized CRUD

use the entity with the name in the mixer

  • default types

       ├── ${value}:mount // change the whole state for a new one
       ├── ${value}:create // unshift an object into
       ├── ${value}:will:update // takes an "updating" property: boolean
       ├── ${value}:update // update properties by fk
       ├── ${value}:will:delete // takes an "deleting" property: boolean
       └── ${value}:delete // delete object by fk
## tools
Mutate a copy of data without changing the original source
this package uses [immutability-helper](https://github.com/kolodny/immutability-helper)

- manage reducer with websocket
[this package is perfect with web socket, see example](https://github.com/mathec-x/lecontrol-client)
0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago