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

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

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