UNPKG

wechaty-redux

Version:

Wechaty Redux Plugin Powered By Ducks

177 lines 5.56 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); /** * Wechaty Open Source Software - https://github.com/wechaty * * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and * Wechaty Contributors <https://github.com/wechaty>. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ const typesafe_actions_1 = require("typesafe-actions"); const actions = __importStar(require("./actions.js")); const initialState = { puppet: {}, wechaty: {}, }; const reducer = (0, typesafe_actions_1.createReducer)(initialState) .handleAction(actions.SCAN_RECEIVED_EVENT, (state, action) => { const newState = { ...state, puppet: { ...state.puppet, [action.meta.puppetId]: { ...state.puppet[action.meta.puppetId], currentUser: undefined, qrcode: action.payload.qrcode, }, }, }; return newState; }) .handleAction([ actions.LOGOUT_RECEIVED_EVENT, actions.STOPPED_EVENT, ], (state, action) => { const newState = { ...state, puppet: { ...state.puppet, [action.meta.puppetId]: { ...state.puppet[action.meta.puppetId], currentUser: undefined, qrcode: undefined, }, }, }; return newState; }) /** * Register & Deregister Puppet */ .handleAction(actions.REGISTER_PUPPET_COMMAND, (state, action) => { const newState = { ...state, puppet: { ...state.puppet, [action.payload.puppetId]: { ...state.puppet[action.payload.puppetId], }, }, }; return newState; }) .handleAction(actions.DEREGISTER_PUPPET_COMMAND, (state, action) => { const newState = { ...state, puppet: { ...state.puppet, [action.payload.puppetId]: undefined, // TODO: how to remove the key with `...`? Huan(202203) }, }; return newState; }) /** * Register & Deregister Wechaty */ .handleAction(actions.REGISTER_WECHATY_COMMAND, (state, action) => { const newState = { ...state, wechaty: { ...state.wechaty, [action.payload.wechatyId]: { ...state.wechaty[action.payload.wechatyId], }, }, }; return newState; }) .handleAction(actions.DEREGISTER_WECHATY_COMMAND, (state, action) => { const newState = { ...state, wechaty: { ...state.wechaty, [action.payload.wechatyId]: undefined, }, }; return newState; }) /** * Bind & Unbind Wechaty <> Puppet */ .handleAction(actions.BIND_WECHATY_PUPPET_COMMAND, (state, action) => { const newState = { ...state, puppet: { ...state.puppet, [action.payload.puppetId]: { ...state.puppet[action.payload.puppetId], wechatyId: action.payload.wechatyId, }, }, wechaty: { ...state.wechaty, [action.payload.wechatyId]: { ...state.wechaty[action.payload.wechatyId], puppetId: action.payload.puppetId, }, }, }; return newState; }) .handleAction(actions.UNBIND_WECHATY_PUPPET_COMMAND, (state, action) => { const newState = { ...state, puppet: { ...state.puppet, [action.payload.puppetId]: { ...state.puppet[action.payload.puppetId], wechatyId: undefined, }, }, wechaty: { ...state.wechaty, [action.payload.wechatyId]: { ...state.wechaty[action.payload.wechatyId], puppetId: undefined, }, }, }; return newState; }); exports.default = reducer; //# sourceMappingURL=reducers.js.map