项目作者: choko-org

项目描述 :
Modular Redux bootstrap with asynchronous side-effects.
高级语言: JavaScript
项目地址: git://github.com/choko-org/redux-boot.git
创建时间: 2016-03-09T01:57:32Z
项目社区:https://github.com/choko-org/redux-boot

开源协议:MIT License

下载


Redux Boot

Modular Redux bootstrap with asynchronous side-effects.

Build Status
sponsored by Taller

What is Redux Boot?

Minimal Framework using Redux to develop modularized universal (backend and frontend) applications, based on functional programming paradigms and friends such as Map and Reduce, Immutability and Reactive programming.

“Simplicity is the ultimate sophistication.”
— Leonardo da Vinci

What Redux Boot provides?

  • Module API - Clean organization and reuse patterns for your code.
  • Async side-effects - No-brainer async side-effects with redux-actions and redux-promise.

Examples:

Documentation

For more details see the documentation.

Getting started

Install

  1. npm install redux-boot --save

Basic Usage

  1. import boot, {BOOT} from 'redux-boot'
  2. const initialState = {
  3. foo: 'bar'
  4. }
  5. const testModule = {
  6. reducer: {
  7. [BOOT]: (state, action) => {
  8. return {
  9. ...state,
  10. foo: 'baz'
  11. }
  12. }
  13. }
  14. }
  15. const modules = [
  16. testModule
  17. ]
  18. const app = boot(initialState, modules)
  19. app.then(({action, store}) => {
  20. // Should print 'baz'.
  21. console.log(store.getState().foo)
  22. })

Sync middleware (with redux-actions)

  1. import boot, {BOOT} from 'redux-boot'
  2. import {createAction} from 'redux-actions'
  3. const CHANGE_FOO = 'redux-boot/test/CHANGE_FOO'
  4. const changeFoo = createAction(CHANGE_FOO)
  5. const initialState = {
  6. foo: 'bar'
  7. }
  8. const testModule = {
  9. reducer: {
  10. [CHANGE_FOO]: (state, action) => {
  11. return {
  12. ...state,
  13. foo: action.payload
  14. }
  15. }
  16. },
  17. middleware: {
  18. [BOOT]: store => next => action => {
  19. store.dispatch(changeFoo('baz'))
  20. return next(action)
  21. }
  22. }
  23. }
  24. const modules = [
  25. testModule
  26. ]
  27. const app = boot(initialState, modules)
  28. app.then(({action, store}) => {
  29. // Should print 'baz'.
  30. console.log(store.getState().foo)
  31. })

Async middleware (with redux-action and redux-promise)

  1. import boot, {BOOT} from 'redux-boot'
  2. import {createAction} from 'redux-actions'
  3. const CHANGE_FOO = 'redux-boot/test/CHANGE_FOO'
  4. const changeFoo = createAction(CHANGE_FOO, async (value) => {
  5. return new Promise((resolve, reject) => {
  6. setTimeout(() => resolve(value), 1)
  7. })
  8. })
  9. const initialState = {
  10. foo: 'bar'
  11. }
  12. const testModule = {
  13. reducer: {
  14. [CHANGE_FOO]: (state, action) => {
  15. return {
  16. ...state,
  17. foo: action.payload
  18. }
  19. }
  20. },
  21. middleware: {
  22. [BOOT]: store => next => async action => {
  23. const result = next(action)
  24. await store.dispatch(changeFoo('baz'))
  25. return result
  26. }
  27. }
  28. }
  29. const modules = [
  30. testModule
  31. ]
  32. const app = boot(initialState, modules)
  33. app.then(({action, store}) => {
  34. // Should print 'baz'.
  35. console.log(store.getState().foo)
  36. })

Development setup:

Install

  1. git clone https://github.com/choko-org/redux-boot.git
  2. npm install

Build

  1. npm run build

Build and Run the tests

  1. npm test

License

MIT