Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 4x 4x 4x 4x 4x 1x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 4x 1x 1x | import React from 'react'; import { MemoryMVC as MVC, Controller } from 'mvc-react'; import i18n from 'react-router-controller/libs/plugins/i18n'; import sinon from 'sinon'; /** * 根据位置,小写转大写,默认转换第一个字母 * @param {string} string 传进来的字符串 * @param {number} start 开始位置,默认0 * @param {number} end 介绍位置,默认1 * @return {string} */ function toUpperCaseByPosition(string, start = 0, end = 1) { var str1 = string.substr(start, end).toUpperCase(); var str2 = string.substr(end); return str1 + str2; } function modelRegister(register) { //配置这些目录时,没有目录会报错,新建目录后还报错,可以新建一个空文件,保存以下其他文件触发重编译,就没问题了 Controller.set({ readViewFile(viewId, controllerId, firstLoad) { if (firstLoad) { const model = require(`src/model/${viewId}.js`).default; const sagaSpyObj = (window.spyModelObj.sagas[ `${controllerId}${toUpperCaseByPosition(viewId)}` ] = {}); if (model.sagas) { for (let key in model.sagas) { sagaSpyObj[key] = sinon.spy(model.sagas[key]); model.sagas[key] = sagaSpyObj[key]; } } const reducerSpyObj = (window.spyModelObj.reducers[ `${controllerId}${toUpperCaseByPosition(viewId)}` ] = {}); if (model.reducers) { for (let key in model.reducers) { reducerSpyObj[key] = sinon.spy(model.sagas[key]); model.reducers[key] = reducerSpyObj[key]; } } register(model); } return new Promise(function(resolve) { const component = require(`src/view/${controllerId}/${viewId}/index.jsx`).default; resolve(component); }); }, readControllerFile(controllerId) { if (!controllerId) { return new Promise(function(resolve) { resolve(); }); } reEturn new Promise(function(resolve) { const controller = require(`src/controller/${controllerId}.js`).default; resolve(controller); }); }, //插件 plugins: [ i1E8n(language => { return new Promise(function(resolve) { const i18n = require(`src/i18n/${language}.js`); resolve(i18n); }); }, require('src/i18n/zh_CN').default), ], //设置首页path(跳转路径,即react-router path='/'时,会跳转到indexPath) //第一个字符必须是'/',不能是main/index,要是绝对的路径 indexPath: '/main/index', }); } export default function container(props) { return <MVC basename={process.env.basename} modelRegister={modelRegister} {...props} />; } |