提交 807600cc authored 作者: vipcxj's avatar vipcxj

1.修复一些lodash转fp版本出现的问题

2.使用storybook-info插件
上级 a55004e2
{
"parser": "babel-eslint",
"extends": "airbnb",
"extends": ["airbnb", "plugin:lodash-fp/recommended"],
"rules": {
"generator-star-spacing": [0],
"consistent-return": [0],
......@@ -34,11 +34,14 @@
"no-await-in-loop": "off",
"prefer-destructuring": "off",
"react/require-default-props": "off",
"react/no-array-index-key": "off"
"react/no-array-index-key": "off",
"lodash-fp/use-fp": "off",
"lodash-fp/no-unused-result": "off"
},
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
}
},
"plugins": ["lodash-fp"]
}
......@@ -37,6 +37,7 @@
"devDependencies": {
"@babel/core": "^7.0.0-beta.40",
"@babel/register": "^7.0.0-beta.40",
"@storybook/addon-info": "^3.3.15",
"@storybook/react": "^3.3.15",
"babel-core": "^7.0.0-bridge.0",
"babel-plugin-dva-hmr": "^0.4.1",
......@@ -48,10 +49,9 @@
"ejs-loader": "^0.3.1",
"enzyme": "^3.3.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-lodash-fp": "^2.1.3",
"http-proxy-middleware": "^0.17.4",
"jsdom": "^11.0.0",
"less": "^2.7.2",
"less-loader": "^4.0.0",
"lodash-webpack-plugin": "^0.11.4",
"mockjs": "^1.0.1-beta3",
"path": "^0.12.7",
......
import React, { Component } from 'react';
import { connect as dvaConnect } from 'dva';
import startsWith from 'lodash/startsWith';
import startsWith from 'lodash/fp/startsWith';
import flow from 'lodash/fp/flow';
import mapKeys from 'lodash/fp/mapKeys';
import pickBy from 'lodash/fp/pickBy';
......@@ -37,8 +37,8 @@ const connect = (modelCreator, { app, mapStateToProps, mapDispatchToProps, merge
props.loading = state.loading;
props.loading.model = props.loading.models[model.namespace];
props.loading.effect = flow(
pickBy((v, k) => startsWith(k, `${model.namespace}/`)),
mapKeys((v, k) => k.slice(model.namespace.length + 1)),
pickBy((v, k) => startsWith(`${model.namespace}/`, k)),
mapKeys(k => k.slice(model.namespace.length + 1)),
)(props.loading.effects);
}
return props;
......
......@@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Router } from 'dva-react-router-3/router';
import isString from 'lodash/isString';
import get from 'lodash/get';
import config from './utils/config';
import { isAuthed, hasDomain, histories } from './utils/auth';
import { fullPath } from './utils/helper';
......@@ -108,7 +109,7 @@ const createRoutes = async (app, modules, groups, basePath) => {
if (route.onEnter) {
const onEnter = route.onEnter;
route.onEnter = (nextState, replace, cb) => {
if (nextState && nextState.location && nextState.location.pathname === route.fullPath) {
if (get(nextState, 'location.pathname') === route.fullPath) {
histories.pushHistory('module', {
name,
showName,
......@@ -130,7 +131,7 @@ const createRoutes = async (app, modules, groups, basePath) => {
};
} else {
route.onEnter = (nextState, replace, cb) => {
if (nextState && nextState.location && nextState.location.pathname === route.fullPath) {
if (get(nextState, 'location.pathname') === route.fullPath) {
histories.pushHistory('module', {
name,
showName,
......
......@@ -2,7 +2,7 @@ import mapKeys from 'lodash/mapKeys';
import toPairs from 'lodash/toPairs';
import isUndefined from 'lodash/isUndefined';
import isString from 'lodash/isString';
import partial from 'lodash/partial';
import partial from 'lodash/fp/partial';
import request from '../utils/request';
import post from '../utils/post';
import { normParams } from '../utils/http-helper';
......@@ -21,29 +21,29 @@ export const datasourceApi = (coordinate) => {
} : (coordinate || {});
if (containerType === 'global') {
return {
query: partial(calcGlobalDatasource, datasourceName),
count: partial(countGlobalDatasource, datasourceName),
cursor: partial(cursorGlobalDatasource, datasourceName),
meta: partial(getGlobalDatasourceMeta, datasourceName),
update: partial(updateGlobalDatasource, datasourceName),
create: partial(createGlobalDatasource, datasourceName),
remove: partial(removeGlobalDatasource, datasourceName),
query: partial(calcGlobalDatasource, [datasourceName]),
count: partial(countGlobalDatasource, [datasourceName]),
cursor: partial(cursorGlobalDatasource, [datasourceName]),
meta: partial(getGlobalDatasourceMeta, [datasourceName]),
update: partial(updateGlobalDatasource, [datasourceName]),
create: partial(createGlobalDatasource, [datasourceName]),
remove: partial(removeGlobalDatasource, [datasourceName]),
validateUpdate: partial(validateUpdateGlobalDatasource, datasourceName),
validateCreate: partial(validateCreateGlobalDatasource, datasourceName),
validateRemove: partial(validateRemoveGlobalDatasource, datasourceName),
};
} else if (containerType === 'module') {
return {
query: partial(calcModuleDatasource, containerName, datasourceName),
count: partial(countModuleDatasource, containerName, datasourceName),
cursor: partial(cursorModuleDatasource, containerName, datasourceName),
meta: partial(getModuleDatasourceMeta, containerName, datasourceName),
update: partial(updateModuleDatasource, containerName, datasourceName),
create: partial(createModuleDatasource, containerName, datasourceName),
remove: partial(removeModuleDatasource, containerName, datasourceName),
validateUpdate: partial(validateUpdateModuleDatasource, containerName, datasourceName),
validateCreate: partial(validateCreateModuleDatasource, containerName, datasourceName),
validateRemove: partial(validateRemoveModuleDatasource, containerName, datasourceName),
query: partial(calcModuleDatasource, [containerName, datasourceName]),
count: partial(countModuleDatasource, [containerName, datasourceName]),
cursor: partial(cursorModuleDatasource, [containerName, datasourceName]),
meta: partial(getModuleDatasourceMeta, [containerName, datasourceName]),
update: partial(updateModuleDatasource, [containerName, datasourceName]),
create: partial(createModuleDatasource, [containerName, datasourceName]),
remove: partial(removeModuleDatasource, [containerName, datasourceName]),
validateUpdate: partial(validateUpdateModuleDatasource, [containerName, datasourceName]),
validateCreate: partial(validateCreateModuleDatasource, [containerName, datasourceName]),
validateRemove: partial(validateRemoveModuleDatasource, [containerName, datasourceName]),
};
} else {
throw new Error(`Unsupported containerType: ${containerType}`);
......
import partial from 'lodash/partial';
import partial from 'lodash/fp/partial';
import _ from 'lodash/fp/placeholder';
import request from '../utils/request';
import post from '../utils/post';
......@@ -9,15 +9,15 @@ import config from '../utils/config';
export const templateApi = (dmPath) => {
return {
admin: {
getInfo: partial(getAdminTemplateInfo, _, dmPath),
getAllInfoes: partial(getAllAdminTemplateInfoes, dmPath),
getConfigure: partial(getAdminTemplateConfigure, _, dmPath),
getPlainConfigure: partial(getAdminTemplatePlainConfigure, _, dmPath),
setConfigure: partial(setAdminTemplateConfigure, _, _, dmPath),
removeConfigure: partial(removeAdminTemplateConfigure, _, dmPath),
getTemplate: partial(getAdminTemplateTemplate, _, dmPath),
setTemplate: partial(setAdminTemplateTemplate, _, _, dmPath),
render: partial(adminRender, _, _, _, dmPath),
getInfo: partial(getAdminTemplateInfo, [_, dmPath]),
getAllInfoes: partial(getAllAdminTemplateInfoes, [dmPath]),
getConfigure: partial(getAdminTemplateConfigure, [_, dmPath]),
getPlainConfigure: partial(getAdminTemplatePlainConfigure, [_, dmPath]),
setConfigure: partial(setAdminTemplateConfigure, [_, _, dmPath]),
removeConfigure: partial(removeAdminTemplateConfigure, [_, dmPath]),
getTemplate: partial(getAdminTemplateTemplate, [_, dmPath]),
setTemplate: partial(setAdminTemplateTemplate, [_, _, dmPath]),
render: partial(adminRender, [_, _, _, dmPath]),
},
};
};
......
/* eslint-disable no-param-reassign */
/** @module utils/db */
import flow from 'lodash/flow';
import get from 'lodash/get';
import set from 'lodash/set';
import unset from 'lodash/unset';
import set from 'lodash/fp/set';
import unset from 'lodash/fp/unset';
import flow from 'lodash/fp/flow';
import getOr from 'lodash/fp/getOr';
import LocalStorage from 'lowdb/adapters/LocalStorage';
import { isPromise } from './helper';
......@@ -108,17 +108,17 @@ const init = function init(db, key, adapter) {
const CreateDB = () => {
function db(path, defaultValue) {
function getValue(...functions) {
const result = get(db.getState(), path, defaultValue);
const result = getOr(defaultValue, path, db.getState());
return flow(...functions)(result);
}
getValue.write = (...args) => {
const result = getValue(...args);
set(db.getState(), path, result);
set(path, result, db.getState());
return db.write();
};
getValue.delete = (flush = true) => {
unset(db.getState(), path);
unset(path, db.getState());
return flush ? db.write() : db.getState();
};
......
/* eslint-disable no-console */
import React from 'react';
import partial from 'lodash/partial';
import partial from 'lodash/fp/partial';
import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import ReactJson from 'react-json-view';
import { DatePicker, Form, Input, Modal, Button } from 'antd';
......@@ -16,7 +17,7 @@ import loginIt from './lib/login';
storiesOf('a', module)
.add('1', () => {
const Comp = lazy(partial(loginIt, 'admin', 'admin', '/'))(dva()(DsTable));
const Comp = lazy(partial(loginIt, ['admin', 'admin', '/']))(dva()(DsTable));
const coordinate = {
containerType: 'module',
containerName: 'test',
......@@ -27,12 +28,12 @@ storiesOf('a', module)
const RangePicker = DatePicker.RangePicker;
storiesOf('antd', module)
.add('RangePicker', () => {
.add('RangePicker', withInfo({ inline: true })(() => {
return <RangePicker />;
})
.add('uca', () => {
}))
.add('uca', withInfo({ inline: true })(() => {
return <UCA onChange={evt => console.log(evt)} />;
});
}));
storiesOf('table-input', module)
.add('1', () => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论