wechaty-redux
v1.20.2
Published
Wechaty Redux Plugin Powered By Ducks
Downloads
2,321
Readme
wechaty-redux
Wrap Wechaty with Redux Actions & Reducers for Easy State Management
Image Source: Managing your React state with Redux
What is Redux
Redux is a Predictable State Container for JS Apps
Why use Redux with Wechaty
To be write...
What is Ducks
See Ducks
Usage
Install
npm install wechaty-redux
Vanilla Redux with Wechaty Redux Plugin
Vanilla Redux means using plain Redux without any additional libraries like Ducks.
import {
createStore,
applyMiddleware,
} from 'redux'
import {
createEpicMiddleware,
combineEpics,
} from 'redux-observable'
import { WechatyBuilder } from 'wechaty'
import {
WechatyRedux,
Api,
} from 'wechaty-redux'
/**
* 1. Configure Store with RxJS Epic Middleware for Wechaty Ducks API
*/
const epicMiddleware = createEpicMiddleware()
const store = createStore(
Api.default,
applyMiddleware(epicMiddleware),
)
const rootEpic = combineEpics(...Object.values(Api.epics))
epicMiddleware.run(rootEpic)
/**
* 2. Instanciate Wechaty and Install Redux Plugin
*/
const bot = WechatyBuilder.build({ puppet: 'wechaty-puppet-mock' })
bot.use(WechatyRedux({ store }))
/**
* 3. Using Redux Store with Wechaty Ducks API!
*/
store.subscribe(() => console.info(store.getState()))
store.dispatch(Api.actions.ding(bot.puppet.id, 'dispatch a ding action'))
// The above code 👆 is exactly do the same thing with the following code 👇 :
Api.operations.ding(store.dispatch)(bot.puppet.id, 'call ding from operations')
Ducks Proposal Style for Wechaty Redux Plugin
import { WechatyBuilder } from 'wechaty'
import { Ducks } from 'ducks'
import {
WechatyRedux,
Api,
} from 'wechaty-redux'
/**
* 1. Ducksify Wechaty Redux API
*/
const ducks = new Ducks({ wechaty: Api })
const store = ducks.configureStore()
/**
* 2. Instanciate Wechaty with Redux Plugin
*/
const bot = WechatyBuilder.build({ puppet: 'wechaty-puppet-mock' })
bot.use(WechatyRedux({ store }))
/**
* 3. Using Redux Store with Wechaty Ducks API!
* (With the Power of Ducks / Ducksify)
*/
const wechatyDuck = ducks.ducksify('wechaty')
store.subscribe(() => console.info(store.getState()))
wechatyDuck.operations.ding(bot.puppet.id, 'Ducksify Style ding!')
Redux Actions
See: api/actions.ts
Redux Operations
See: api/operations.ts
Ducks Api
See: api/index.ts
API Docs
Links
CQRS
Chatbot in Redux
- Building bots with Redux
- BotBuilder v3 Node.js bot with Redux state management
- 🐺 Declarative development for state driven dynamic prompt flow
- Botbuilder Redux Middleware
- Botbuilder Redux Common Package
Redux Tools
- Redux DevTools
- Remote Redux DevTools
- Using Redux DevTools in production
- Video - Getting Started with Redux Dev Tools
Redux Talks
- Dan Abramov - Live React: Hot Reloading with Time Travel at react-europe 2015
- Dan Abramov - The Redux Journey at react-europe 2016
- Debugging javascript applications in production - Mihail Diordiev
Redux Middleware
Redux Enhancers
Articles
Useful Modules
History
main
v1.20 (Mar 7, 2022)
- Refactoring all events with breaking changes for better CQRS Wechaty support.
- Refactoring the events name convension: from
eventName
toEVENT_NAME
v1.0 (Oct 28, 2021)
Release v1.0 of Wechaty Redux (thanks @mukaiu)
v0.5
- Upgrade RxJS version from 6 to 7.1
- ES Modules support
v0.2 (Jun 2, 2020)
Initial version. Requires [email protected]
or above versions.
WechatyRedux
Plugin is ready to use.- API follows the Ducks specification.
v0.0.1 (Apr 19, 2020)
Decide to build a Redux Plugin for Wechaty.
Related Projects:
- A library that exposes matrix-js-sdk state via Redux
- A library for managing network state in Redux
- How to setup Redux for a REST api
- Redux middleware for calling an API
Author
Huan LI (李卓桓) [email protected]
Copyright & License
- Code & Docs © 2020 Huan (李卓桓) <[email protected]>
- Code released under the Apache-2.0 License
- Docs released under Creative Commons