Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
4fd3d930
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4fd3d930
编写于
6月 04, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(harmony): defineXXXApi
上级
da3bfd9b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
91 addition
and
12 deletion
+91
-12
packages/uni-runtime/src/helpers/api/index.ts
packages/uni-runtime/src/helpers/api/index.ts
+84
-11
packages/uni-runtime/src/index.ts
packages/uni-runtime/src/index.ts
+7
-1
未找到文件。
packages/uni-runtime/src/helpers/api/index.ts
浏览文件 @
4fd3d930
import
{
defineAsyncApi
as
originalDefineAsyncApi
,
//
defineOffApi as originalDefineOffApi,
//
defineOnApi as originalDefineOnApi,
//
defineSyncApi as originalDefineSyncApi,
//
defineTaskApi as originalDefineTaskApi,
defineOffApi
as
originalDefineOffApi
,
defineOnApi
as
originalDefineOnApi
,
defineSyncApi
as
originalDefineSyncApi
,
defineTaskApi
as
originalDefineTaskApi
,
}
from
'
@dcloudio/uni-runtime
'
type
Anything
=
Object
|
null
|
undefined
...
...
@@ -44,14 +44,10 @@ function getPropType(type: string | NullType): Anything {
if
(
!
type
)
{
return
}
return
TYPE_MAP
[
type
]
return
TYPE_MAP
.
get
(
type
)
}
export
function
defineAsyncApi
<
T
extends
AsyncMethodOptionLike
,
K
>
(
name
:
string
,
fn
:
(
options
:
T
,
res
:
ApiExcutor
<
K
>
)
=>
void
,
protocol
:
Map
<
string
,
ProtocolOptions
>
,
options
:
ApiOptions
<
T
>
):
Function
{
function
buildProtocol
(
protocol
:
Map
<
string
,
ProtocolOptions
>
)
{
const
originalProtocol
=
{}
as
Record
<
string
,
Object
>
protocol
.
forEach
((
value
,
key
)
=>
{
const
protocol
=
(
originalProtocol
[
key
]
=
{}
as
Record
<
string
,
Anything
>
)
...
...
@@ -60,6 +56,10 @@ export function defineAsyncApi<T extends AsyncMethodOptionLike, K>(
protocol
.
required
=
value
.
required
protocol
.
validator
=
value
.
validator
})
return
originalProtocol
}
function
buildOptions
(
options
:
ApiOptions
<
AsyncMethodOptionLike
>
)
{
const
originalFormatArgs
=
{}
as
Record
<
string
,
Function
>
if
(
options
.
formatArgs
)
{
options
.
formatArgs
.
forEach
((
value
,
key
)
=>
{
...
...
@@ -71,6 +71,19 @@ export function defineAsyncApi<T extends AsyncMethodOptionLike, K>(
originalOptions
.
beforeAll
=
options
.
beforeAll
originalOptions
.
beforeSuccess
=
options
.
beforeSuccess
originalOptions
.
formatArgs
=
originalFormatArgs
return
originalOptions
}
export
function
defineAsyncApi
<
T
extends
AsyncMethodOptionLike
,
K
>
(
name
:
string
,
fn
:
(
options
:
T
,
res
:
ApiExcutor
<
K
>
)
=>
void
,
protocol
:
Map
<
string
,
ProtocolOptions
>
,
options
:
ApiOptions
<
T
>
):
Function
{
const
originalProtocol
=
buildProtocol
(
protocol
)
const
originalOptions
=
buildOptions
(
options
as
ApiOptions
<
AsyncMethodOptionLike
>
)
return
originalDefineAsyncApi
(
name
,
// @ts-expect-error
...
...
@@ -79,3 +92,63 @@ export function defineAsyncApi<T extends AsyncMethodOptionLike, K>(
originalOptions
)
}
export
function
defineTaskApi
<
T
,
K
>
(
name
:
string
,
fn
:
(
options
:
T
,
res
:
ApiExcutor
<
K
>
)
=>
void
,
protocol
:
Map
<
string
,
ProtocolOptions
>
,
options
:
ApiOptions
<
T
>
):
Object
{
const
originalProtocol
=
buildProtocol
(
protocol
)
const
originalOptions
=
buildOptions
(
options
as
ApiOptions
<
AsyncMethodOptionLike
>
)
return
originalDefineTaskApi
(
name
,
// @ts-expect-error
fn
,
originalProtocol
,
originalOptions
)
}
export
function
defineSyncApi
<
T
,
K
>
(
name
:
string
,
fn
:
(
options
:
T
)
=>
K
,
protocol
:
Map
<
string
,
ProtocolOptions
>
,
options
:
ApiOptions
<
T
>
):
Object
{
const
originalProtocol
=
buildProtocol
(
protocol
)
const
originalOptions
=
buildOptions
(
options
as
ApiOptions
<
AsyncMethodOptionLike
>
)
return
originalDefineSyncApi
(
name
,
fn
,
// @ts-expect-error
originalProtocol
,
originalOptions
)
}
export
function
defineOnApi
<
T
>
(
name
:
string
,
fn
:
()
=>
void
,
options
:
ApiOptions
<
T
>
):
Function
{
const
originalOptions
=
buildOptions
(
options
as
ApiOptions
<
AsyncMethodOptionLike
>
)
return
originalDefineOnApi
(
name
,
fn
,
originalOptions
)
}
export
function
defineOffApi
<
T
>
(
name
:
string
,
fn
:
()
=>
void
,
options
:
ApiOptions
<
T
>
):
Function
{
const
originalOptions
=
buildOptions
(
options
as
ApiOptions
<
AsyncMethodOptionLike
>
)
return
originalDefineOffApi
(
name
,
fn
,
originalOptions
)
}
packages/uni-runtime/src/index.ts
浏览文件 @
4fd3d930
...
...
@@ -8,7 +8,13 @@ export {
}
from
'
@vue/shared
'
// export * from './helpers/api'
export
{
defineAsyncApi
}
from
'
@dcloudio/uni-api
'
export
{
defineAsyncApi
,
defineSyncApi
,
defineTaskApi
,
defineOnApi
,
defineOffApi
,
}
from
'
@dcloudio/uni-api
'
export
{
Emitter
}
from
'
@dcloudio/uni-shared
'
export
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
export
const
__uniConfig
=
globalThis
.
__uniConfig
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录