Skip to content

Commit 578b1e2

Browse files
author
ChenYong
committed
switching to lodash-es; alpha release
1 parent 5cfeec4 commit 578b1e2

18 files changed

Lines changed: 58 additions & 52 deletions

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jimengio/code-rule-editor",
3-
"version": "0.1.0",
3+
"version": "0.1.1-a1",
44
"description": "Code rule editor of JimengIO",
55
"main": "lib/index.js",
66
"scripts": {
@@ -32,7 +32,7 @@
3232
"@jimengio/safe-property": "^0.0.2",
3333
"@jimengio/shared-utils": "^0.1.5",
3434
"@types/antd": "^1.0.0",
35-
"@types/lodash": "^4.14.149",
35+
"@types/lodash-es": "^4.17.3",
3636
"@types/node": "^12.12.21",
3737
"@types/prettier": "^1.19.0",
3838
"@types/query-string": "^6.3.0",
@@ -69,7 +69,6 @@
6969
"decimal.js": "^10.2.0",
7070
"emotion": "^10.0.23",
7171
"immer": "^5.0.2",
72-
"lodash": "^4.17.15",
7372
"lodash-es": "^4.17.15",
7473
"query-string": "^6.9.0",
7574
"react": "^16.12.0",

src/code-rule-view.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component } from "react";
2-
import _ from "lodash";
32
import { css, cx } from "emotion";
43
import produce from "immer";
54

src/editor.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import _ from "lodash";
2+
import { map, merge, fromPairs, isEmpty, isNil, every, toPairs } from "lodash-es";
33
import { css, cx } from "emotion";
44
import produce from "immer";
55

@@ -64,7 +64,7 @@ export default class CodeRuleEditor extends React.Component<IProps, IState> {
6464
}
6565

6666
getFormsFromSegments(segments: ICodeRule[]) {
67-
return _.map(segments, (segment) => _.merge({ type: segment.type }, _.fromPairs(_.map(segment.settings, (setting) => [setting.name, setting.value]))));
67+
return map(segments, (segment) => merge({ type: segment.type }, fromPairs(map(segment.settings, (setting) => [setting.name, setting.value]))));
6868
}
6969

7070
setImmerState = immerHelpers.immerState as ImmerStateFunc<IState>;
@@ -83,7 +83,7 @@ export default class CodeRuleEditor extends React.Component<IProps, IState> {
8383
isFocused={idx === this.state.focusedPosition}
8484
movingPosition={this.state.movingPosition}
8585
droppingPosition={this.state.droppingPosition}
86-
failuresHighlighted={!_.isEmpty(this.state.listedFailures[idx])}
86+
failuresHighlighted={!isEmpty(this.state.listedFailures[idx])}
8787
onClick={() => {
8888
this.setImmerState((state) => {
8989
state.focusedPosition = idx;
@@ -149,7 +149,7 @@ export default class CodeRuleEditor extends React.Component<IProps, IState> {
149149
}
150150

151151
renderForm(form, failures: any[]) {
152-
if (_.isNil(form)) {
152+
if (isNil(form)) {
153153
return null;
154154
}
155155
switch (form.type) {
@@ -374,11 +374,11 @@ export default class CodeRuleEditor extends React.Component<IProps, IState> {
374374
onConfirm = () => {
375375
let listedFailures = this.getValidationResults(this.state.formList);
376376

377-
if (_.every(listedFailures, _.isEmpty)) {
377+
if (every(listedFailures, isEmpty)) {
378378
let newSegments = this.state.formList.map((form) => {
379379
return {
380380
type: form.type,
381-
settings: _.map(_.toPairs(form), (pair) => {
381+
settings: map(toPairs(form), (pair) => {
382382
return { name: pair[0], value: `${pair[1]}` };
383383
}).filter((pair) => pair.name !== "type"),
384384
};

src/forms/auto-increment-form.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import _ from "lodash";
2+
import { last, isEmpty } from "lodash-es";
33
import produce from "immer";
44
import InputNumber from "antd/lib/input-number";
55
import Select from "antd/lib/select";
@@ -117,7 +117,7 @@ export default class AutoIncrementImmerForm extends React.Component<IProps, ISta
117117
onChange={(value: string) => {
118118
this.props.onSubmit(
119119
produce(form, (draft) => {
120-
draft.paddingCharactor = _.last((value as string) || "0");
120+
draft.paddingCharactor = last((value as string) || "0");
121121
})
122122
);
123123
}}
@@ -151,19 +151,19 @@ export default class AutoIncrementImmerForm extends React.Component<IProps, ISta
151151
export let validateAutoIncrementForm = (form: ICodeRuleFormAutoIncrement) => {
152152
let result: any = {};
153153

154-
// if (_.isEmpty(form.scope)) {
154+
// if (isEmpty(form.scope)) {
155155
// result.scope = lang.dataIsRequired;
156156
// }
157157

158158
if (form.length == null) {
159159
result.length = lang.invalidInput;
160160
}
161161

162-
if (_.isEmpty(form.period)) {
162+
if (isEmpty(form.period)) {
163163
result.period = lang.dataIsRequired;
164164
}
165165

166-
if (_.isEmpty(form.paddingCharactor)) {
166+
if (isEmpty(form.paddingCharactor)) {
167167
result.paddingCharactor = lang.dataIsRequired;
168168
}
169169

src/forms/checksum-form.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import _ from "lodash";
2+
import { last, isEmpty } from "lodash-es";
33
import produce from "immer";
44
import InputNumber from "antd/lib/input-number";
55
import Select from "antd/lib/select";
@@ -101,7 +101,7 @@ export default class ChecksumImmerForm extends React.Component<IProps, IState> {
101101
onChange={(value: string) => {
102102
this.props.onSubmit(
103103
produce(form, (draft) => {
104-
draft.paddingCharactor = _.last((value as string) || "0");
104+
draft.paddingCharactor = last((value as string) || "0");
105105
})
106106
);
107107
}}
@@ -119,11 +119,11 @@ export const validateChecksumForm = (form: ICodeRuleFormChecksum) => {
119119
result.length = lang.invalidInput;
120120
}
121121

122-
if (_.isEmpty(form.paddingCharactor)) {
122+
if (isEmpty(form.paddingCharactor)) {
123123
result.paddingCharactor = lang.dataIsRequired;
124124
}
125125

126-
if (_.isEmpty(form.algorithm)) {
126+
if (isEmpty(form.algorithm)) {
127127
result.algorithm = lang.dataIsRequired;
128128
}
129129

src/forms/literal-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import _ from "lodash";
2+
import { isEmpty } from "lodash-es";
33
import produce from "immer";
44

55
import { styleFormContainer, styleFormRowsList, LabeledField, LabeledFieldInput } from "../immer-form";
@@ -73,7 +73,7 @@ export default class LiteralImmerForm extends React.Component<IProps, IState> {
7373
export const validateLiteralForm = (form: ICodeRuleFormLiteral) => {
7474
let result: any = {};
7575

76-
if (_.isEmpty(form.content)) {
76+
if (isEmpty(form.content)) {
7777
result.content = lang.contentRequired;
7878
}
7979

src/forms/parameter-value-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import _ from "lodash";
2+
import { isEmpty } from "lodash-es";
33
import produce from "immer";
44

55
import { styleFormContainer, styleFormRowsList, LabeledField, LabeledFieldInput } from "../immer-form";
@@ -73,7 +73,7 @@ export default class ParameterValueImmerForm extends React.Component<IProps, ISt
7373
export const validateParameterValueForm = (form: ICodeRuleFormParameterValue) => {
7474
let result: any = {};
7575

76-
if (_.isEmpty(form.parameterName)) {
76+
if (isEmpty(form.parameterName)) {
7777
result.parameterName = lang.parameterNameRequired;
7878
}
7979

src/forms/user-input-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import _ from "lodash";
2+
import { isEmpty } from "lodash-es";
33
import produce from "immer";
44

55
import { styleFormContainer, styleFormRowsList, LabeledField, LabeledFieldInput } from "../immer-form";
@@ -98,7 +98,7 @@ export const validateUserInputForm = (form: ICodeRuleFormUserInput) => {
9898
result.length = lang.invalidInput;
9999
}
100100

101-
if (_.isEmpty(form.parameterName)) {
101+
if (isEmpty(form.parameterName)) {
102102
result.parameterName = lang.parameterNameRequired;
103103
}
104104

src/forms/year-form.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
import _ from "lodash";
32
import produce from "immer";
43
import Select from "antd/lib/select";
54

src/immer-form.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import * as React from "react";
66
import { CSSProperties, ReactNode } from "react";
7-
import _ from "lodash";
7+
import { isString, values, isNil, isObject } from "lodash-es";
88
import { css, cx } from "emotion";
99
import { inlineRow, column, row, flex } from "@jimengio/flex-styles";
1010
import { lang, formatString } from "./lingual";
@@ -50,7 +50,7 @@ export const validationMethods = {
5050

5151
if (data == null) {
5252
return defaultFailed;
53-
} else if (_.isString(data)) {
53+
} else if (isString(data)) {
5454
if (data.length === 0) {
5555
return defaultFailed;
5656
}
@@ -104,7 +104,7 @@ export const validationMethods = {
104104

105105
// function outdated, see https://github.com/beego/fi/pull/1247
106106
export function isFailuresEmpty(failures: object): boolean {
107-
return _.values(failures).every(_.isNil);
107+
return values(failures).every(isNil);
108108
}
109109

110110
// form rows
@@ -135,10 +135,10 @@ let renderFailure = (failure) => {
135135
if (failure == null) {
136136
return null;
137137
}
138-
if (_.isString(failure)) {
138+
if (isString(failure)) {
139139
return <div className={styleFormInvalid}>{failure}</div>;
140140
}
141-
if (_.isObject(failure)) {
141+
if (isObject(failure)) {
142142
let failureInfo = failure as IFailureInfo;
143143
switch (failureInfo.type) {
144144
case "warning":

0 commit comments

Comments
 (0)