1.0.6 • Published 10 years ago

redux-connect-actions v1.0.6

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

redux-connect-actions

Redux helper to handle actions

Install

$ npm i --save redux-connect-actions

Usage

//constants.js

const constants = {
  ADD_TODO: 'ADD_TODO',
  SET_VISIBILITY_FILTER: 'SET_VISIBILITY_FILTER',
}

//actions.js
import connectActions from 'redux-connect-actions'
import constants from './constants'

function addTodo(state, action){
  return Object.assign({}, state, {
    todos: [...state.todos, {
      text: action.payload,
      completed: false
    }]
  })
}

function setVisibilityFilter(state, action){
  return Object.assign({}, state, {
    visibilityFilter: action.filter
  })
}

export default connectActions({
  [constants.ADD_TODO]: addTodo,
  [constants.SET_VISIBILITY_FILTER]: setVisibilityFilter
})

//index.js
function todoApp = createStore(
  connectActions(actionMap, initialState)
)

API

connectionActions(actionMap [, initialState [, defaultFn]])

  • actionMap - an object which maps an action.type to a function to handle that action. Whenever an action with a specific type goes through redux, if a key with that name is found in the actionMap object, the corresponding function is called, since it's assigned to handle that action.

  • initialState - optional

  • defaultFn - optional. If no matching function found, the defaultFn will be called

License

MIT

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago