Zone 底座:二义性处理
Methods
(static) ambAnnex(reference, name, propFirst) → {Object}
「标准」Ux.ambAnnex
该方法是一个合并方法,替换原始方法中的Ux.pass
函数,主要逻辑如下:
- 在
props
和state
中提取Object类型的变量,并执行合并 - 如果 propFirst = true,则属性中的Object类型变量优先,最终结果使用 props -> state 的合并
- 如果 propFirst = false, 则状态中的Object类型变量优先,最终结果则使用 state -> props 的合并
注意 props 中的内容是不可变更的,这种情况下,此处需要拷贝新对象返回,最终形成合并结果, 如果其中一方没有值,则两个值会同态合并,无影响
Parameters:
Name | Type | Default | Description |
---|---|---|---|
reference |
Object | ReactComponent | React组件引用,通常是reference统一变量名 |
|
name |
String | 字符串变量名 |
|
propFirst |
Boolean |
true
|
属性优先还是状态优先 |
Returns:
返回最终的值
- Type
- Object
(static) ambArray(args) → {Array}
「标准」Ux.ambArray
二义性函数数组规范化
- 如果 args 本身是数组,则直接返回 args,并且过滤掉 undefined 的元素。
- 如果 args 的第一个元素是数组,则直接返回第一个元素,并且过滤掉 undefined 的元素。
- 如果 args 不是数组,也不是变参数组,则直接使用
[]
修饰过后返回最终数组。
框架内部的使用代码:
// 支持三种输入数据格式
// args 变参:("path1","path2");
// args 数组:(["path1","path2"]);
// args 修饰:("path1");
const fromPath = (reference = {}, ...args) => {
let keys = Ele.ambArray.apply(this, args);
const length = keys['length'];
// ... 其他代码部分
}
Parameters:
Name | Type | Description |
---|---|---|
args |
Array.<any> | Array | 传入的二义性参数信息 |
Returns:
返回最终的数组信息
- Type
- Array
(static) ambDatetime(input, fields, source)
「标准」Ux.ambDatetime
Parameters:
Name | Type | Description |
---|---|---|
input |
||
fields |
||
source |
(static) ambEvent(event, config, defaultValue) → {any}
「标准」Ux.ambEvent
二义性Event读取专用函数
- Input触发时,直接从
event.target.value
中读取相关数据。 - 表单直接触发或Select触发,则
event
就是value,包括onSearch
,这种情况直接将event
作为读取值。
Parameters:
Name | Type | Description |
---|---|---|
event |
Event | Object | 传入方法和Ant Design中常用的 event 参数 |
config |
Object | 是否启用 |
defaultValue |
any | 默认值,如果没有读取到值则使用默认值 |
Returns:
返回最终读取到的值。
- Type
- any
(static) ambFind(props, key, name) → {any}
「标准」Ux.ambFind
二义性数据提取专用函数
- 传入
key
和name
,提取属性或状态之下的"对象包含的属性"值。 - 一级提取:可能返回Object,也可能返回DataObject。
- 二级提取:任意值。
框架内的使用代码如:
const targetKey = attrPath[0];
const name = attrPath[1];
if (targetKey && name) {
return Ele.ambFind(target, `$${targetKey}`, attrPath[1]);
} else {
console.error(`[ Ux ] 解析的配置不对,key = $${targetKey}, name = ${name}`);
}
Parameters:
Name | Type | Description |
---|---|---|
props |
Props | State | 传入的React组件的状态或属性对象 |
key |
String | 待提取的属性名或状态名称,提取内容必须是一个 |
name |
Array | String | 待提取的二级属性名 |
Returns:
返回最终提取的值。
- Type
- any
(static) ambKv(input, fnKv) → {any}
「标准」Ux.ambKv
二义性遍历函数
- 如果输入的是 Object,则直接遍历,并且传入参数
(key, value)
给 fnKv。 - 如果输入的的 Array,则遍历每一个 Object 元素,将元素的遍历信息
(key, value)
传入 fnKv。
Parameters:
Name | Type | Description |
---|---|---|
input |
Object | Array | 输入的被遍历的源 |
fnKv |
function | key=value 的处理函数 |
Returns:
返回fnKv
的执行结果
- Type
- any
(static) ambObject(reference, name, propFirst) → {Object}
「标准」Ux.ambObject
二义性合并专用函数
- 直接从 reference 的 props 或 state 中提取属性名为
name
的值。 - 如果无值则直接返回
{}
。
框架内部代码:
const yoHistory = (reference) => {
const $inited = Ux.ambObject(reference, "$inited");
const {activity = {}, changes = []} = $inited;
// 其他处理代码……
}
该方法可确保函数永远返回一个合法的Object,而不受其他数据干扰,最终应用于一些常用的默认值为{}
的场景。
Parameters:
Name | Type | Default | Description |
---|---|---|---|
reference |
Object | ReactComponent | React组件引用,通常是reference统一变量名 |
|
name |
String | 字符串变量名称,读取变量值专用 |
|
propFirst |
Boolean |
true
|
判断优先级,默认优先级 props |
Returns:
返回最终的值
- Type
- Object
(static) ambValue(reference, name, propFirst) → {any}
「标准」Ux.ambValue
二义性专用提取数据函数
- 先从
props
中提取属性为 name 的值。 - 如果无法从
props
中提取,则直接从state
中提取对应的值。
框架内部代码:
const $submitting = Ele.ambValue(reference, "$submitting");
Parameters:
Name | Type | Default | Description |
---|---|---|---|
reference |
Object | ReactComponent | React组件引用,通常是reference统一变量名 |
|
name |
String | 字符串变量名称,读取变量值专用 |
|
propFirst |
Boolean |
true
|
判断优先级,默认优先级 props |
Returns:
返回变量对应的值
- Type
- any