Match-id-376100c85662cffb23b28ed1f31fb28473ed51a5

This commit is contained in:
* 2023-06-07 15:12:51 +08:00
parent 6175b4e308
commit 04181677ea
13 changed files with 25 additions and 35 deletions

View File

@ -17,7 +17,7 @@
*
*/
import { getIFrameFocusedDom, isNull, isText } from './utils/Common';
import { getIFrameFocusedDom, isText } from './utils/Common';
import { isElement } from './utils/Common';
@ -30,7 +30,7 @@ function setSelectionRange(dom: HTMLInputElement | HTMLTextAreaElement, range) {
const { start, end } = range;
let realEnd = end;
if (isNull(realEnd)) {
if (realEnd === null || realEnd === undefined) {
realEnd = start;
}

View File

@ -85,6 +85,6 @@ export function shouldAutoFocus(tagName: string, props: Props): boolean {
return types.includes(tagName) ? Boolean(props.autoFocus) : false;
}
export function isNull(val) {
return val === null || val === undefined;
export function isNotNull(object: any): boolean {
return object !== null && object !== undefined;
}

View File

@ -14,7 +14,6 @@
*/
import { getPropDetails, PROPERTY_TYPE, PropDetails } from './PropertiesData';
import { isNull } from '../utils/Common';
const INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
@ -74,7 +73,7 @@ export function isInvalidValue(
propDetails: PropDetails | null,
isNativeTag: boolean
): boolean {
if (isNull(value)) {
if (value === null || value === undefined) {
return true;
}
@ -105,7 +104,7 @@ export function validateProps(type, props) {
}
// style属性必须是对象
if (!isNull(props.style) && typeof props.style !== 'object') {
if (props.style !== null && props.style !== undefined && typeof props.style !== 'object') {
throw new Error('style should be a object.');
}

View File

@ -15,7 +15,6 @@
import { updateCommonProp } from '../DOMPropertiesHandler/UpdateCommonProp';
import { Props } from '../utils/Interface';
import { isNull } from '../utils/Common';
function getInitValue(dom: HTMLInputElement, props: Props) {
const { value, defaultValue, checked, defaultChecked } = props;
@ -30,7 +29,7 @@ function getInitValue(dom: HTMLInputElement, props: Props) {
export function getInputPropsWithoutValue(dom: HTMLInputElement, props: Props) {
// checked属于必填属性无法置
let { checked } = props;
if (isNull(checked)) {
if (checked === undefined) {
checked = getInitValue(dom, props).initChecked;
}
@ -46,12 +45,12 @@ export function getInputPropsWithoutValue(dom: HTMLInputElement, props: Props) {
export function updateInputValue(dom: HTMLInputElement, props: Props) {
const { value, checked } = props;
if (!isNull(value)) {
if (value !== undefined) {
// 处理 dom.value 逻辑
if (dom.value !== String(value)) {
dom.value = String(value);
}
} else if (!isNull(checked)) {
} else if (checked !== undefined) {
updateCommonProp(dom, 'checked', checked, true);
}
}
@ -61,7 +60,7 @@ export function setInitInputValue(dom: HTMLInputElement, props: Props) {
const { value, defaultValue } = props;
const { initValue, initChecked } = getInitValue(dom, props);
if (!isNull(value) || !isNull(defaultValue)) {
if (value !== undefined || defaultValue !== undefined) {
// value 的使用优先级 value 属性 > defaultValue 属性 > 空字符串
const initValueStr = String(initValue);

View File

@ -14,7 +14,6 @@
*/
import { HorizonSelect, Props } from '../utils/Interface';
import { isNull } from '../utils/Common';
function updateMultipleValue(options, newValues) {
const newValueSet = new Set();
@ -70,18 +69,18 @@ export function updateSelectValue(dom: HorizonSelect, props: Props, isInit = fal
dom._multiple = newMultiple;
// 设置了 value 属性
if (!isNull(value)) {
if (value !== null && value !== undefined) {
updateValue(dom.options, value, newMultiple);
} else if (oldMultiple !== newMultiple) {
// 修改了 multiple 属性
// 切换 multiple 之后,如果设置了 defaultValue 需要重新应用
if (!isNull(defaultValue)) {
if (defaultValue !== null && defaultValue !== undefined) {
updateValue(dom.options, defaultValue, newMultiple);
} else {
// 恢复到未选定状态
updateValue(dom.options, newMultiple ? [] : '', newMultiple);
}
} else if (isInit && !isNull(defaultValue)) {
} else if (isInit && defaultValue !== null && defaultValue !== undefined) {
// 设置了 defaultValue 属性
updateValue(dom.options, defaultValue, newMultiple);
}

View File

@ -14,13 +14,12 @@
*/
import { Props } from '../utils/Interface';
import { isNull } from '../utils/Common';
// 值的优先级 value > children > defaultValue
function getInitValue(props: Props) {
const { value } = props;
if (isNull(value)) {
if (value === undefined) {
const { defaultValue, children } = props;
let initValue = defaultValue;

View File

@ -73,7 +73,7 @@ export function lazyDelegateOnRoot(currentRoot: VNode, eventName: string) {
const nativeFullName = isCapture ? nativeEvent + 'capture' : nativeEvent;
// 事件存储在DOM节点属性避免多个VNode(root和portal)对应同一个DOM, 造成事件重复监听
currentRoot.realNode.$EV = currentRoot.realNode.$EV || {};
currentRoot.realNode.$EV = currentRoot.realNode.$EV ?? {};
const events = currentRoot.realNode.$EV;
if (!events[nativeFullName]) {

View File

@ -14,7 +14,7 @@
*/
import { getVNodeProps } from '../dom/DOMInternalKeys';
import { getDomTag, isNull } from '../dom/utils/Common';
import { getDomTag, isNotNull } from '../dom/utils/Common';
import { Props } from '../dom/utils/Interface';
import { updateTextareaValue } from '../dom/valueHandler/TextareaValueHandler';
import { updateInputHandlerIfChanged } from '../dom/valueHandler/ValueChangeHandler';
@ -41,14 +41,14 @@ function controlInputValue(inputDom: HTMLInputElement, props: Props) {
const { name, type } = props;
// 如果是 radio找出同一form内name相同的Radio更新它们Handler的Value
if (type === 'radio' && !isNull(name)) {
if (type === 'radio' && isNotNull(name)) {
const radioList = document.querySelectorAll<HTMLInputElement>(`input[type="radio"][name="${name}"]`);
for (let i = 0; i < radioList.length; i++) {
const radio = radioList[i];
if (radio === inputDom) {
continue;
}
if (!isNull(radio.form) && !isNull(inputDom.form) && radio.form !== inputDom.form) {
if (isNotNull(radio.form) && isNotNull(inputDom.form) && radio.form !== inputDom.form) {
continue;
}

View File

@ -54,7 +54,6 @@ import {
import { getPathArr } from './utils/vNodePath';
import { injectUpdater } from '../external/devtools';
import { popCurrentRoot, pushCurrentRoot } from './RootStack';
import { isNull } from '../dom/utils/Common';
// 不可恢复错误
let unrecoverableErrorDuringBuild: any = null;
@ -140,7 +139,7 @@ function bubbleVNode(vNode: VNode): void {
node = parent;
// 更新processing抛出异常时可以使用
processing = node;
} while (!isNull(node));
} while (node);
// 修改结果
if (getBuildResult() === BuildInComplete) {
@ -181,7 +180,7 @@ function getChildByIndex(vNode: VNode, idx: number) {
let node = vNode.child;
for (let i = 0; i < idx; i++) {
// 场景当组件被销毁业务若异步定时器调用setState修改状态可能出现路径错误此处进行保护。
if (isNull(node)) {
if (node === null || node === undefined) {
return null;
}
@ -226,7 +225,7 @@ export function calcStartUpdateVNode(treeRoot: VNode) {
const pathIndex = Number(startNodePath[i]);
node = getChildByIndex(node, pathIndex)!;
// 路径错误时,回退到从根更新
if (isNull(node)) {
if (node === null) {
return treeRoot;
}
}

View File

@ -17,10 +17,7 @@ import { useLayoutEffectImpl } from './UseEffectHook';
import { getHookStage } from './HookStage';
import { throwNotInFuncError } from './BaseHook';
import type { Ref } from './HookType';
function isNotNull(object: any): boolean {
return object !== null && object !== undefined;
}
import { isNotNull } from '../../dom/utils/Common';
function effectFunc<R>(func: () => R, ref: Ref<R> | ((any) => any) | null): (() => void) | null {
if (typeof ref === 'function') {

View File

@ -23,7 +23,6 @@ import { markRef } from './BaseComponent';
import { DomComponent, DomPortal, DomText } from '../vnode/VNodeTags';
import { travelVNodeTree } from '../vnode/VNodeUtils';
import { createChildrenByDiff } from '../diff/nodeDiffComparator';
import { isNull } from '../../dom/utils/Common';
function updateDom(processing: VNode, type: any, newProps: Props) {
// 如果oldProps !== newProps意味着存在更新并且需要处理其相关的副作用
@ -55,7 +54,7 @@ export function bubbleRender(processing: VNode) {
const type = processing.type;
const newProps = processing.props;
if (!processing.isCreated && !isNull(processing.realNode)) {
if (!processing.isCreated && processing.realNode !== null) {
// 更新dom属性
updateDom(processing, type, newProps);

View File

@ -27,7 +27,7 @@ export function captureRender(): VNode | null {
export function bubbleRender(processing: VNode) {
const newText = processing.props;
if (!processing.isCreated && !isNull(processing.realNode)) {
if (!processing.isCreated && processing.realNode !== null) {
// 更新
const oldText = processing.oldProps;
// 如果文本不同,将其标记为更新

View File

@ -44,7 +44,6 @@ import {
import { VNode } from './VNode';
import { JSXElement, Source } from '../Types';
import { markVNodePath } from '../utils/vNodePath';
import { isNull } from '../../dom/utils/Common';
const typeLazyMap = {
[TYPE_FORWARD_REF]: ForwardRef,
@ -137,7 +136,7 @@ export function createUndeterminedVNode(type, key, props, source: Source | null)
vNodeTag = typeMap[type.vtype];
isLazy = type.vtype === TYPE_LAZY;
} else {
throw Error(`Component type is invalid, got: ${isNull(type) ? type : componentType}`);
throw Error(`Component type is invalid, got: ${type === null || type === undefined ? type : componentType}`);
}
const vNode = newVirtualNode(vNodeTag, key, props);