项目作者: redradix

项目描述 :
Generic redux reducers, actions and selectors.
高级语言: JavaScript
项目地址: git://github.com/redradix/reduken.git
创建时间: 2018-02-05T10:50:57Z
项目社区:https://github.com/redradix/reduken

开源协议:

下载


Discontinued in flavor of Redukers

We have decided to evolve this package but with a completely new concept of only reusable reducers and selectors. You can read more about this idea in the Redukers repo.
You can still use this package but it won’t be maintained any longer.


Reduken

Generic redux reducers, actions and selectors.

Downloads
Version
License
Dependencies
Size

Set-up with React & Redux

  1. Install reduken
    1. npm install reduken
  2. Set up redux reducers

    1. import { combineReducers } from 'redux'
    2. import { entities, hash, list, requests, enableBatching } from 'reduken'
    3. export default enableBatching(combineReducers({
    4. entities,
    5. hash,
    6. list,
    7. requests
    8. }))

Modules

Also one utility available

Full Example

  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3. import { createStore, combineReducers } from 'redux'
  4. import { connect, Provider } from 'react-redux'
  5. import { entities, hash, list, requests, enableBatching } from 'reduken'
  6. import { set, getFromPath } from 'reduken/hash'
  7. // 1. Create store with the reduken reducers
  8. const rootReducer = combineReducers({
  9. entities,
  10. hash,
  11. list,
  12. requests
  13. })
  14. const store = createStore(enableBatching(rootReducer), window.__INITIAL_STATE__)
  15. // 2. Presentational Component
  16. const HelloComponent = ({ name, handleChange }) => {
  17. return (
  18. <div>
  19. <h1>Hello {name}</h1>
  20. <input type="text" onChange={handleChange} value={name} />
  21. </div>
  22. )
  23. }
  24. // 3. Decorate component with connect
  25. const HelloDecorated = connect(
  26. state => ({
  27. name: getFromPath('session', 'name', state) || 'World'
  28. }),
  29. {
  30. handleChange: event => set('session', 'name', event.target.value)
  31. }
  32. )(HelloComponent)
  33. // 4. Render the app
  34. ReactDOM.render(
  35. <Provider store={store}>
  36. <HelloDecorated ></HelloDecorated>
  37. </Provider>,
  38. document.getElementById('root')
  39. )