Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
fad6292a
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fad6292a
编写于
11月 18, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): support multiple arguments
上级
c54d85e1
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
79 addition
and
27 deletion
+79
-27
packages/uni-api/src/helpers/api/promise.ts
packages/uni-api/src/helpers/api/promise.ts
+8
-3
packages/uni-api/src/helpers/interceptor.ts
packages/uni-api/src/helpers/interceptor.ts
+1
-1
packages/uni-cli-shared/src/mp/template.ts
packages/uni-cli-shared/src/mp/template.ts
+1
-1
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+14
-10
packages/uni-mp-core/src/api/promise.ts
packages/uni-mp-core/src/api/promise.ts
+7
-3
packages/uni-mp-kuaishou/dist/uni.compiler.js
packages/uni-mp-kuaishou/dist/uni.compiler.js
+1
-1
packages/uni-mp-kuaishou/src/compiler/options.ts
packages/uni-mp-kuaishou/src/compiler/options.ts
+1
-1
packages/uni-mp-weixin/__tests__/component.spec.ts
packages/uni-mp-weixin/__tests__/component.spec.ts
+38
-1
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+4
-4
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+2
-1
packages/uni-mp-weixin/src/compiler/options.ts
packages/uni-mp-weixin/src/compiler/options.ts
+2
-1
未找到文件。
packages/uni-api/src/helpers/api/promise.ts
浏览文件 @
fad6292a
...
@@ -27,15 +27,20 @@ export function handlePromise(promise: Promise<unknown>) {
...
@@ -27,15 +27,20 @@ export function handlePromise(promise: Promise<unknown>) {
}
}
export
function
promisify
(
name
:
string
,
fn
:
Function
)
{
export
function
promisify
(
name
:
string
,
fn
:
Function
)
{
return
(
args
=
{})
=>
{
return
(
args
=
{}
,
...
rest
:
unknown
[]
)
=>
{
if
(
hasCallback
(
args
))
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
))
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
))
}
}
return
wrapperReturnValue
(
return
wrapperReturnValue
(
name
,
name
,
handlePromise
(
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}))
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
)
})
})
)
)
)
)
...
...
packages/uni-api/src/helpers/interceptor.ts
浏览文件 @
fad6292a
...
@@ -115,7 +115,7 @@ export function invokeApi(
...
@@ -115,7 +115,7 @@ export function invokeApi(
method
:
string
,
method
:
string
,
api
:
Function
,
api
:
Function
,
options
:
object
,
options
:
object
,
...
params
:
[]
params
:
unknown
[]
)
{
)
{
const
interceptor
=
getApiInterceptorHooks
(
method
)
const
interceptor
=
getApiInterceptorHooks
(
method
)
if
(
interceptor
&&
Object
.
keys
(
interceptor
).
length
)
{
if
(
interceptor
&&
Object
.
keys
(
interceptor
).
length
)
{
...
...
packages/uni-cli-shared/src/mp/template.ts
浏览文件 @
fad6292a
...
@@ -8,7 +8,7 @@ export interface MiniProgramCompilerOptions {
...
@@ -8,7 +8,7 @@ export interface MiniProgramCompilerOptions {
* 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
* 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
*/
*/
lazyElement
?:
{
lazyElement
?:
{
[
name
:
string
]:
string
[]
[
name
:
string
]:
{
name
:
'
on
'
|
'
bind
'
;
arg
:
string
[]
}
[]
}
}
event
?:
{
event
?:
{
format
(
format
(
...
...
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
fad6292a
...
@@ -213,16 +213,20 @@ function isLazyElement(node: ElementNode, context: TemplateCodegenContext) {
...
@@ -213,16 +213,20 @@ function isLazyElement(node: ElementNode, context: TemplateCodegenContext) {
if
(
!
context
.
lazyElement
)
{
if
(
!
context
.
lazyElement
)
{
return
false
return
false
}
}
const
events
=
context
.
lazyElement
[
node
.
tag
]
const
lazyProps
=
context
.
lazyElement
[
node
.
tag
]
return
(
if
(
!
lazyProps
)
{
events
&&
return
node
.
props
.
some
(
}
(
prop
)
=>
return
node
.
props
.
some
(
prop
.
type
===
NodeTypes
.
DIRECTIVE
&&
(
prop
)
=>
prop
.
name
===
'
on
'
&&
prop
.
type
===
NodeTypes
.
DIRECTIVE
&&
prop
.
arg
?.
type
===
NodeTypes
.
SIMPLE_EXPRESSION
&&
lazyProps
.
find
((
lazyProp
)
=>
{
events
.
includes
(
prop
.
arg
.
content
)
return
(
)
prop
.
name
===
lazyProp
.
name
&&
prop
.
arg
?.
type
===
NodeTypes
.
SIMPLE_EXPRESSION
&&
lazyProp
.
arg
.
includes
(
prop
.
arg
.
content
)
)
})
)
)
}
}
/**
/**
...
...
packages/uni-mp-core/src/api/promise.ts
浏览文件 @
fad6292a
...
@@ -66,13 +66,16 @@ export function promisify(name: string, api: unknown) {
...
@@ -66,13 +66,16 @@ export function promisify(name: string, api: unknown) {
if
(
!
isFunction
(
api
))
{
if
(
!
isFunction
(
api
))
{
return
api
return
api
}
}
return
function
promiseApi
(
options
:
Record
<
string
,
any
>
=
{})
{
return
function
promiseApi
(
options
:
Record
<
string
,
any
>
=
{},
...
rest
:
unknown
[]
)
{
if
(
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
)
isFunction
(
options
.
complete
)
)
{
)
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
))
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
rest
))
}
}
return
wrapperReturnValue
(
return
wrapperReturnValue
(
name
,
name
,
...
@@ -84,7 +87,8 @@ export function promisify(name: string, api: unknown) {
...
@@ -84,7 +87,8 @@ export function promisify(name: string, api: unknown) {
extend
({},
options
,
{
extend
({},
options
,
{
success
:
resolve
,
success
:
resolve
,
fail
:
reject
,
fail
:
reject
,
})
}),
rest
)
)
})
})
)
)
...
...
packages/uni-mp-kuaishou/dist/uni.compiler.js
浏览文件 @
fad6292a
...
@@ -147,7 +147,7 @@ const miniProgram = {
...
@@ -147,7 +147,7 @@ const miniProgram = {
},
},
directive
:
'
ks:
'
,
directive
:
'
ks:
'
,
lazyElement
:
{
lazyElement
:
{
switch
:
[
'
change
'
],
switch
:
[
{
name
:
'
on
'
,
arg
:
[
'
change
'
]
}
],
},
},
};
};
const
projectConfigFilename
=
'
project.config.json
'
;
const
projectConfigFilename
=
'
project.config.json
'
;
...
...
packages/uni-mp-kuaishou/src/compiler/options.ts
浏览文件 @
fad6292a
...
@@ -32,7 +32,7 @@ export const miniProgram: MiniProgramCompilerOptions = {
...
@@ -32,7 +32,7 @@ export const miniProgram: MiniProgramCompilerOptions = {
},
},
directive
:
'
ks:
'
,
directive
:
'
ks:
'
,
lazyElement
:
{
lazyElement
:
{
switch
:
[
'
change
'
],
switch
:
[
{
name
:
'
on
'
,
arg
:
[
'
change
'
]
}
],
},
},
}
}
const
projectConfigFilename
=
'
project.config.json
'
const
projectConfigFilename
=
'
project.config.json
'
...
...
packages/uni-mp-weixin/__tests__/component.spec.ts
浏览文件 @
fad6292a
...
@@ -11,7 +11,7 @@ describe('mp-weixin: transform component', () => {
...
@@ -11,7 +11,7 @@ describe('mp-weixin: transform component', () => {
}`
}`
)
)
})
})
test
(
'
lazy element
'
,
()
=>
{
test
(
'
lazy element
: editor
'
,
()
=>
{
assert
(
assert
(
`<editor/>`
,
`<editor/>`
,
`<editor/>`
,
`<editor/>`
,
...
@@ -24,6 +24,43 @@ describe('mp-weixin: transform component', () => {
...
@@ -24,6 +24,43 @@ describe('mp-weixin: transform component', () => {
`<block wx:if="{{r0}}"><editor bindready="{{a}}"/></block>`
,
`<block wx:if="{{r0}}"><editor bindready="{{a}}"/></block>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _o(_ctx.ready) }
return { a: _o(_ctx.ready) }
}`
)
})
test
(
'
lazy element: canvas
'
,
()
=>
{
assert
(
`<canvas/>`
,
`<canvas/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<canvas canvas-id="myCanvas" id="myCanvas"/>`
,
`<canvas canvas-id="myCanvas" id="myCanvas"/>`
,
`(_ctx, _cache) => {
return {}
}`
)
assert
(
`<canvas :id="id"/>`
,
`<block wx:if="{{r0}}"><canvas id="{{a}}"/></block>`
,
`(_ctx, _cache) => {
return { a: _ctx.id }
}`
)
assert
(
`<canvas :canvas-id="id"/>`
,
`<block wx:if="{{r0}}"><canvas canvas-id="{{a}}"/></block>`
,
`(_ctx, _cache) => {
return { a: _ctx.id }
}`
)
assert
(
`<canvas :canvas-id="id" :id="id"/>`
,
`<block wx:if="{{r0}}"><canvas canvas-id="{{a}}" id="{{b}}"/></block>`
,
`(_ctx, _cache) => {
return { a: _ctx.id, b: _ctx.id }
}`
}`
)
)
})
})
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
fad6292a
...
@@ -236,7 +236,7 @@ function getApiInterceptorHooks(method) {
...
@@ -236,7 +236,7 @@ function getApiInterceptorHooks(method) {
}
}
return
interceptor
;
return
interceptor
;
}
}
function
invokeApi
(
method
,
api
,
options
,
...
params
)
{
function
invokeApi
(
method
,
api
,
options
,
params
)
{
const
interceptor
=
getApiInterceptorHooks
(
method
);
const
interceptor
=
getApiInterceptorHooks
(
method
);
if
(
interceptor
&&
Object
.
keys
(
interceptor
).
length
)
{
if
(
interceptor
&&
Object
.
keys
(
interceptor
).
length
)
{
if
(
isArray
(
interceptor
.
invoke
))
{
if
(
isArray
(
interceptor
.
invoke
))
{
...
@@ -586,17 +586,17 @@ function promisify(name, api) {
...
@@ -586,17 +586,17 @@ function promisify(name, api) {
if
(
!
isFunction
(
api
))
{
if
(
!
isFunction
(
api
))
{
return
api
;
return
api
;
}
}
return
function
promiseApi
(
options
=
{})
{
return
function
promiseApi
(
options
=
{}
,
...
rest
)
{
if
(
isFunction
(
options
.
success
)
||
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
))
{
isFunction
(
options
.
complete
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
));
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
rest
));
}
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
api
,
extend
({},
options
,
{
invokeApi
(
name
,
api
,
extend
({},
options
,
{
success
:
resolve
,
success
:
resolve
,
fail
:
reject
,
fail
:
reject
,
}));
})
,
rest
);
})));
})));
};
};
}
}
...
...
packages/uni-mp-weixin/dist/uni.compiler.js
浏览文件 @
fad6292a
...
@@ -72,7 +72,8 @@ const miniProgram = {
...
@@ -72,7 +72,8 @@ const miniProgram = {
},
},
directive
:
'
wx:
'
,
directive
:
'
wx:
'
,
lazyElement
:
{
lazyElement
:
{
editor
:
[
'
ready
'
],
canvas
:
[{
name
:
'
bind
'
,
arg
:
[
'
canvas-id
'
,
'
id
'
]
}],
editor
:
[{
name
:
'
on
'
,
arg
:
[
'
ready
'
]
}],
},
},
};
};
const
projectConfigFilename
=
'
project.config.json
'
;
const
projectConfigFilename
=
'
project.config.json
'
;
...
...
packages/uni-mp-weixin/src/compiler/options.ts
浏览文件 @
fad6292a
...
@@ -25,7 +25,8 @@ export const miniProgram: MiniProgramCompilerOptions = {
...
@@ -25,7 +25,8 @@ export const miniProgram: MiniProgramCompilerOptions = {
},
},
directive
:
'
wx:
'
,
directive
:
'
wx:
'
,
lazyElement
:
{
lazyElement
:
{
editor
:
[
'
ready
'
],
canvas
:
[{
name
:
'
bind
'
,
arg
:
[
'
canvas-id
'
,
'
id
'
]
}],
editor
:
[{
name
:
'
on
'
,
arg
:
[
'
ready
'
]
}],
},
},
}
}
const
projectConfigFilename
=
'
project.config.json
'
const
projectConfigFilename
=
'
project.config.json
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录