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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -44,7 +44,6 @@ import {
import { VNode } from './VNode'; import { VNode } from './VNode';
import { JSXElement, Source } from '../Types'; import { JSXElement, Source } from '../Types';
import { markVNodePath } from '../utils/vNodePath'; import { markVNodePath } from '../utils/vNodePath';
import { isNull } from '../../dom/utils/Common';
const typeLazyMap = { const typeLazyMap = {
[TYPE_FORWARD_REF]: ForwardRef, [TYPE_FORWARD_REF]: ForwardRef,
@ -137,7 +136,7 @@ export function createUndeterminedVNode(type, key, props, source: Source | null)
vNodeTag = typeMap[type.vtype]; vNodeTag = typeMap[type.vtype];
isLazy = type.vtype === TYPE_LAZY; isLazy = type.vtype === TYPE_LAZY;
} else { } 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); const vNode = newVirtualNode(vNodeTag, key, props);