Skip to content

Commit

Permalink
chore: improve by codereview
Browse files Browse the repository at this point in the history
  • Loading branch information
YSMJ1994 committed Feb 21, 2024
1 parent a766c7b commit 6dbd480
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 83 deletions.
5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

37 changes: 0 additions & 37 deletions cypress/support/commands.ts

This file was deleted.

3 changes: 2 additions & 1 deletion cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="cypress" />

import { mount } from 'cypress/react';
import './commands';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
Expand Down
39 changes: 9 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"component"
],
"dependencies": {
"@alifd/validate": "^2.0.1",
"@alifd/validate": "^2.0.2",
"tslib": "^2.6.2"
},
"devDependencies": {
Expand Down
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, MutableRefObject } from 'react';
import Validate from '@alifd/validate';
import { NormalizedValidateError } from '@alifd/validate/lib/types';
import type { Component, MutableRefObject } from 'react';
import Validate, { type NormalizedValidateError } from '@alifd/validate';
import {
getValueFromEvent,
getErrorStrs,
Expand All @@ -14,7 +13,7 @@ import {
cloneToRuleArr,
isOverwritten,
} from './utils';
import {
import type {
FieldOption,
ComponentInstance,
GetUseFieldOption,
Expand Down Expand Up @@ -59,7 +58,6 @@ class Field {
};
}

private com: ComponentInstance;
private fieldsMeta: Record<string, FieldMeta>;
private cachedBind: Record<string, Record<string, unknown>>;
private instance: Record<string, unknown>;
Expand All @@ -69,6 +67,7 @@ class Field {
private values: FieldValues;
private processErrorMessage?: FieldOption['processErrorMessage'];
private afterValidateRerender?: FieldOption['afterValidateRerender'];
com: ComponentInstance;
options: NormalizedFieldOption;

constructor(com: ComponentInstance, options: FieldOption = {}) {
Expand Down Expand Up @@ -259,8 +258,8 @@ class Field {
id: id || name,
ref: this._getCacheBind(name, `${name}__ref`, this._saveRef),
[valueName]: setValueFormatter
? setValueFormatter(field.value as any, field.inputValues)
: (field.value as any),
? setValueFormatter(field.value as ValueType, field.inputValues)
: field.value,
};

let rulesMap: Record<string, Omit<Rule, 'trigger'>[]> = {};
Expand Down Expand Up @@ -1095,7 +1094,10 @@ class Field {
cache[action] = hander;
}

private _getCache<R = unknown>(name: string, action: string): R | undefined {
/**
* FIXME 有一些地方用到了这些内部函数 (如 deep),先不声明为 private
*/
_getCache<R = unknown>(name: string, action: string): R | undefined {
const cache = this.cachedBind[name] || {};
return cache[action] as R | undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MessagesConfig, PresetFormatter, Validator } from '@alifd/validate/lib/types';
import type { MessagesConfig, PresetFormatter, Validator } from '@alifd/validate';
import type { Component, useState, useMemo, Dispatch, SetStateAction, Ref, RefCallback } from 'react';

export { Validator };
Expand Down

0 comments on commit 6dbd480

Please sign in to comment.