4.2.0 • Published 4 years ago

aerux v4.2.0

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

aerux

node npm license Build Status Standard - JavaScript Style Guide Coverage Status codecov Known Vulnerabilities

An easy way to use redux with react

Install

npm install aerux

Use

// es6
import { createStore, createModel, connect, actions } from 'aerux'
// or
const { createStore, createModel, connect, actions } = require('aerux')

const store = createStore(options)

// reducers/count.js
import { createModel } from 'aerux'

export const { actions, reducer } = createModel({
  namespace: 'count',
  state: 0,
  actions: {
    plus: count => count,
    minus: count => count
  },
  reducers: {
    plus: (state, { payload }) => state + payload,
    minus: (state, { payload }) => state - payload
  }
})

// Count.jsx
import { connect } from 'aerux'

class Count extends React.Component {
  render() {
    // ...
  }
}

export default connect(state => ({
  count: state.count
}))(Count)

// App.jsx
import { Provider } from 'react-redux'
import Count from './Count'

const App = () => (
  <Provider store={store}>
    <Count />
  </Provider>
)

API

createStore

create store with redux.createStore

createStore({
  middlewares,
  enhancers,
  compose,
  state,
  reducers
})
namedescriptiontypedefaultoptional
middlewaresredux middlewareArray[]true
enhancersredux enhancerArray[]true
composeused for redux devtool-redux.composetrue
stateinitial stateany{}true
reducersinitial reducersReducersMapObject{}true

createModel

create model with redux-actions

const { actions, reducer } = createModel({
  namespace,
  state,
  actions,
  reducers
})
namedescriptiontypedefaultoptional
namespacenamespacestringundefinedfalse
stateinitial stateanynulltrue
actionsredux actionsActionMap<Payload, Meta>true
reducersaction handlersReduxCompatibleReducer<State, Action<Payload>> | ReduxCompatibleReducerMeta<State, Action<Payload>, any>{}true

Note: if you create model after create store, you can use actions from aerux directly

Notes

  • namespace: if you present namespace and store is created, reducer will be auto injected to store

  • actions: actionCreator is created by redux-actions

  • reducers: created by redux-actions

actions

action which created in createModel will be auto injected to it, you can call it directly

actions[namespace][actionName]

actions.count.add()

connect

connect store and component like redux.connect, but much better

connect(mapStateToProps, actions)(Component)

Note: you can use actions from aerux directly, no connect actions need, ex:

import { actions } from 'aerux'

class DemoComponent extends React.Component {
  add = () => {
    actions.count.add()
  }
  render() {
    // ...
  }
}

connect(mapStateToProps)(DemoComponent)

store.actions[namespace][actionName]

another alias for actions

store.actions.count.add()

store.injectReducer

This function is used for async inject reducer, for code-splitting

store.hotReplaceReducer

This function is used for HMR when build application with Webpack

4.2.0

4 years ago

4.1.3

4 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.3.2

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.5.2

5 years ago

1.5.0

5 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-beta.2

6 years ago

1.0.0-beta.1

6 years ago

1.0.0-beta.0

6 years ago