UNPKG

wechaty-redux

Version:

Wechaty Redux Plugin Powered By Ducks

70 lines 3.66 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 }); exports.resetEpic = exports.dingEpic = void 0; /** * 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 rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const gerror_1 = require("gerror"); const mod_js_1 = require("../registry/mod.js"); const actions = __importStar(require("./actions.js")); /** * @private Commands - Redux * * Wechaty Redux provide the minimum commands for the system state management: * 1. ding: request the `dong` event * 2. reset: reset the Wechaty state * * For more commands, please refer to the Wechaty CQRS: * @link https://github.com/wechaty/cqrs */ const dingEpic = actions$ => actions$.pipe((0, operators_1.filter)((0, typesafe_actions_1.isActionOf)(actions.DING_COMMAND)), (0, operators_1.mergeMap)(action => (0, rxjs_1.of)((0, mod_js_1.getPuppet)(action.meta.puppetId)).pipe((0, operators_1.mergeMap)(puppet => puppet ? (0, rxjs_1.of)(puppet.ding(action.payload.data)) : rxjs_1.EMPTY), (0, operators_1.ignoreElements)(), (0, operators_1.catchError)(e => (0, rxjs_1.of)(actions.ERROR_RECEIVED_EVENT(action.meta.puppetId, { gerror: gerror_1.GError.stringify(e) })))))); exports.dingEpic = dingEpic; const resetEpic = actions$ => actions$.pipe((0, operators_1.filter)((0, typesafe_actions_1.isActionOf)(actions.RESET_COMMAND)), (0, operators_1.mergeMap)(action => (0, rxjs_1.of)((0, mod_js_1.getPuppet)(action.meta.puppetId)).pipe((0, operators_1.mergeMap)(puppet => puppet ? (0, rxjs_1.of)(puppet.reset()) : rxjs_1.EMPTY), (0, operators_1.ignoreElements)(), (0, operators_1.catchError)((e) => (0, rxjs_1.of)(actions.ERROR_RECEIVED_EVENT(action.meta.puppetId, { gerror: gerror_1.GError.stringify(e) })))))); exports.resetEpic = resetEpic; //# sourceMappingURL=epics.js.map