项目作者: wechaty

项目描述 :
Wechaty Redux Plugin, Reducer Bundle, and Ducks Proposal Implementation.
高级语言: TypeScript
项目地址: git://github.com/wechaty/redux.git
创建时间: 2020-04-19T06:28:31Z
项目社区:https://github.com/wechaty/redux

开源协议:Apache License 2.0

下载


wechaty-redux

NPM Version
NPM
Ducksify Extension
Powered by Ducks
ES Modules

Wrap Wechaty with Redux Actions & Reducers for Easy State Management

Wechaty Redux

Image Source: Managing your React state with Redux

Downloads
TypeScript

What is Redux

Redux is a Predictable State Container for JS Apps

Why use Redux with Wechaty

To be write…

What is Ducks

Ducksify Extension

See Ducks

Usage

Install

  1. npm install wechaty-redux

Vanilla Redux with Wechaty Redux Plugin

Vanilla Redux means using plain Redux without any additional libraries like Ducks.

  1. import {
  2. createStore,
  3. applyMiddleware,
  4. } from 'redux'
  5. import {
  6. createEpicMiddleware,
  7. combineEpics,
  8. } from 'redux-observable'
  9. import { WechatyBuilder } from 'wechaty'
  10. import {
  11. WechatyRedux,
  12. Api,
  13. } from 'wechaty-redux'
  14. /**
  15. * 1. Configure Store with RxJS Epic Middleware for Wechaty Ducks API
  16. */
  17. const epicMiddleware = createEpicMiddleware()
  18. const store = createStore(
  19. Api.default,
  20. applyMiddleware(epicMiddleware),
  21. )
  22. const rootEpic = combineEpics(...Object.values(Api.epics))
  23. epicMiddleware.run(rootEpic)
  24. /**
  25. * 2. Instanciate Wechaty and Install Redux Plugin
  26. */
  27. const bot = WechatyBuilder.build({ puppet: 'wechaty-puppet-mock' })
  28. bot.use(WechatyRedux({ store }))
  29. /**
  30. * 3. Using Redux Store with Wechaty Ducks API!
  31. */
  32. store.subscribe(() => console.info(store.getState()))
  33. store.dispatch(Api.actions.ding(bot.puppet.id, 'dispatch a ding action'))
  34. // The above code 👆 is exactly do the same thing with the following code 👇 :
  35. Api.operations.ding(store.dispatch)(bot.puppet.id, 'call ding from operations')

Ducks Proposal Style for Wechaty Redux Plugin

  1. import { WechatyBuilder } from 'wechaty'
  2. import { Ducks } from 'ducks'
  3. import {
  4. WechatyRedux,
  5. Api,
  6. } from 'wechaty-redux'
  7. /**
  8. * 1. Ducksify Wechaty Redux API
  9. */
  10. const ducks = new Ducks({ wechaty: Api })
  11. const store = ducks.configureStore()
  12. /**
  13. * 2. Instanciate Wechaty with Redux Plugin
  14. */
  15. const bot = WechatyBuilder.build({ puppet: 'wechaty-puppet-mock' })
  16. bot.use(WechatyRedux({ store }))
  17. /**
  18. * 3. Using Redux Store with Wechaty Ducks API!
  19. * (With the Power of Ducks / Ducksify)
  20. */
  21. const wechatyDuck = ducks.ducksify('wechaty')
  22. store.subscribe(() => console.info(store.getState()))
  23. wechatyDuck.operations.ding(bot.puppet.id, 'Ducksify Style ding!')

Redux Actions

See: api/actions.ts

Redux Operations

See: api/operations.ts

Ducks Api

Ducksify Extension

See: api/index.ts

API Docs

CQRS

  1. Command–query separation

Chatbot in Redux

  1. Building bots with Redux
  2. BotBuilder v3 Node.js bot with Redux state management
  3. 🐺 Declarative development for state driven dynamic prompt flow
  4. Botbuilder Redux Middleware
  5. Botbuilder Redux Common Package

Redux Tools

  1. Redux DevTools
  2. Remote Redux DevTools
  3. @zalmoxis/using-redux-devtools-in-production-4c5b56c5600f">Using Redux DevTools in production
  4. Video - Getting Started with Redux Dev Tools

Redux Talks

Redux Middleware

Redux Enhancers

Articles

  1. Setting Up a Redux Project With Create-React-App
  2. Redux is half of a pattern

Useful Modules

  1. redux-automata - Finite state automaton for Redux.

History

main

v1.20 (Mar 7, 2022)

  1. Refactoring all events with breaking changes
    for better CQRS Wechaty support.
  2. Refactoring the events name convension: from eventName to EVENT_NAME

v1.0 (Oct 28, 2021)

Release v1.0 of Wechaty Redux (thanks @mukaiu)

v0.5

  1. Upgrade RxJS version from 6 to 7.1
  2. ES Modules support

v0.2 (Jun 2, 2020)

Initial version. Requires wechaty@0.40 or above versions.

  1. WechatyRedux Plugin is ready to use.
  2. API follows the Ducks specification.

v0.0.1 (Apr 19, 2020)

Decide to build a Redux Plugin for Wechaty.

Related Projects:

  1. A library that exposes matrix-js-sdk state via Redux
  2. A library for managing network state in Redux
  3. How to setup Redux for a REST api
  4. Redux middleware for calling an API

Author

Huan LI (李卓桓) zixia@zixia.net

Profile of Huan LI (李卓桓) on StackOverflow

  • Code & Docs © 2020 Huan (李卓桓) \zixia@zixia.net\
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons