-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from kaiyuanshe/ha
Add High Available mode support
- Loading branch information
Showing
33 changed files
with
732 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/// <reference path="./typings.d.ts" /> | ||
/** | ||
* VERSION | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createAction } from '@reduxjs/toolkit' | ||
|
||
import * as types from './types' | ||
|
||
export const mo = createAction(types.MO) | ||
export const mt = createAction(types.MT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import reducer from './reducers' | ||
|
||
// export { default as counterSelectors } from './selectors' | ||
// export { default as counterOperations } from './operations' | ||
|
||
import * as counterActions from './actions' | ||
import * as counterTypes from './types' | ||
import * as counterSelectors from './selectors' | ||
|
||
export { | ||
counterActions, | ||
counterSelectors, | ||
counterTypes, | ||
} | ||
|
||
export default reducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// import { | ||
|
||
// } from './actions' | ||
|
||
// // This is a link to an action defined in actions.js. | ||
// export const simpleQuack = actions.quack | ||
|
||
// // This is a thunk which dispatches multiple actions from actions.js | ||
// export const complexQuack = ( distance ) => ( dispatch ) => { | ||
// dispatch( actions.quack( ) ).then( ( ) => { | ||
// dispatch( actions.swim( distance ) ); | ||
// dispatch( /* any action */ ); | ||
// } ); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
createReducer, | ||
} from '@reduxjs/toolkit' | ||
|
||
import * as types from './types' | ||
// import * as actions from './actions' | ||
|
||
const initialState = { | ||
mo: 0, | ||
mt: 0, | ||
} as types.State | ||
|
||
const moReducer = (state: types.State) => ({ | ||
...state, | ||
mo: state.mo + 1, | ||
}) | ||
|
||
const mtReducer = (state: types.State) => ({ | ||
...state, | ||
mt: state.mt + 1, | ||
}) | ||
|
||
const counterReducer = createReducer( | ||
initialState, | ||
{ | ||
[types.MO]: moReducer, | ||
[types.MT]: mtReducer, | ||
}, | ||
) | ||
|
||
export default counterReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as types from './types' | ||
|
||
export function mo ( | ||
state: types.State, | ||
) { | ||
return state.mo | ||
} | ||
|
||
export function mt ( | ||
state: types.State, | ||
) { | ||
return state.mt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// import expect from 'expect.js' | ||
// import reducer from './reducers' | ||
// import actions from './actions' | ||
|
||
// describe('duck reducer', function( ) { | ||
// describe('quack', function( ) { | ||
// const quack = actions.quack( ) | ||
// const initialState = false | ||
|
||
// const result = reducer( initialState, quack ) | ||
|
||
// it( 'should quack', function( ) { | ||
// expect( result ).to.be( true ) | ||
// } ) | ||
// } ) | ||
// } ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const MO = 'osschat/wechaty/message/mo' | ||
export const MT = 'osschat/wechaty/message/mt' | ||
|
||
export interface State { | ||
mo: number, | ||
mt: number, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Huan(202003): Redux with Ducks | ||
* | ||
* Scaling your Redux App with ducks: | ||
* https://www.freecodecamp.org/news/scaling-your-redux-app-with-ducks-6115955638be/ | ||
* | ||
* Redux Toolkit - Usage With TypeScript: | ||
* https://redux-toolkit.js.org/usage/usage-with-typescript | ||
* | ||
*/ | ||
import { combineReducers } from 'redux' | ||
import { configureStore } from '@reduxjs/toolkit' | ||
|
||
import logonoff, { | ||
logonoffActions, | ||
logonoffSelectors, | ||
} from './logonoff' | ||
import counter, { | ||
counterActions, | ||
counterSelectors, | ||
} from './counter' | ||
|
||
export { | ||
logonoffActions, | ||
logonoffSelectors, | ||
|
||
counterActions, | ||
counterSelectors, | ||
} | ||
|
||
const reducer = combineReducers({ | ||
counter, | ||
logonoff, | ||
}) | ||
|
||
export const store = configureStore({ | ||
reducer, | ||
}) | ||
|
||
store.subscribe(() => { | ||
console.info('state:', store.getState()) | ||
}) | ||
|
||
export type RootState = ReturnType<typeof reducer> | ||
export type AppDispatch = typeof store.dispatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
createAction, | ||
} from '@reduxjs/toolkit' | ||
|
||
import * as types from './types' | ||
|
||
const prepareScan = ( | ||
id: string, | ||
qrcode: string, | ||
) => { | ||
const payload = { | ||
id, | ||
qrcode, | ||
} | ||
return { payload } | ||
} | ||
|
||
const prepareLogin = ( | ||
id: string, | ||
userName: string, | ||
) => { | ||
const payload = { | ||
id, | ||
userName, | ||
} | ||
return { payload } | ||
} | ||
|
||
const prepareLogout = ( | ||
id: string, | ||
) => { | ||
const payload = { | ||
id, | ||
} | ||
return { payload } | ||
} | ||
|
||
export const scan = createAction(types.SCAN, prepareScan) | ||
export const login = createAction(types.LOGIN, prepareLogin) | ||
export const logout = createAction(types.LOGOUT, prepareLogout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import reducer from './reducers' | ||
|
||
import * as logonoffSelectors from './selectors' | ||
// export { default as duckOperations } from './operations' | ||
import * as logonoffTypes from './types' | ||
import * as logonoffActions from './actions' | ||
|
||
export { | ||
logonoffActions, | ||
logonoffSelectors, | ||
logonoffTypes, | ||
} | ||
|
||
export default reducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// import { | ||
|
||
// } from './actions' | ||
|
||
// // This is a link to an action defined in actions.js. | ||
// export const simpleQuack = actions.quack | ||
|
||
// // This is a thunk which dispatches multiple actions from actions.js | ||
// export const complexQuack = ( distance ) => ( dispatch ) => { | ||
// dispatch( actions.quack( ) ).then( ( ) => { | ||
// dispatch( actions.swim( distance ) ); | ||
// dispatch( /* any action */ ); | ||
// } ); | ||
// } |
Oops, something went wrong.