Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
a85a6788
U
uni-app
项目概览
DCloud
/
uni-app
4 个月 前同步成功
通知
731
Star
38707
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看板
提交
a85a6788
编写于
10月 24, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(v3): subscribe-handlers
上级
b616d099
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
134 addition
and
14 deletion
+134
-14
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+18
-9
packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
.../webpack-uni-pages-loader/lib/platforms/app-plus/index.js
+2
-1
src/platforms/app-plus/service/framework/navigator.js
src/platforms/app-plus/service/framework/navigator.js
+3
-0
src/platforms/app-plus/service/framework/plugins/vdom-sync.js
...platforms/app-plus/service/framework/plugins/vdom-sync.js
+6
-3
src/platforms/app-plus/service/framework/subscribe-handlers/index.js
...ms/app-plus/service/framework/subscribe-handlers/index.js
+30
-0
src/platforms/app-plus/service/framework/subscribe-handlers/on-vd-sync-callback.js
...rvice/framework/subscribe-handlers/on-vd-sync-callback.js
+9
-0
src/platforms/app-plus/service/framework/subscribe-handlers/on-vd-sync.js
...p-plus/service/framework/subscribe-handlers/on-vd-sync.js
+23
-0
src/platforms/app-plus/service/framework/subscribe-handlers/on-webview-ready.js
.../service/framework/subscribe-handlers/on-webview-ready.js
+39
-0
src/platforms/app-plus/service/framework/webview/index.js
src/platforms/app-plus/service/framework/webview/index.js
+4
-1
未找到文件。
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
a85a6788
...
...
@@ -6246,7 +6246,10 @@ var serviceContext = (function () {
function
createPreloadWebview
()
{
if
(
!
preloadWebview
||
preloadWebview
.
__uniapp_route
)
{
// 不存在,或已被使用
preloadWebview
=
plus
.
webview
.
create
(
VIEW_WEBVIEW_PATH
,
String
(
id
++
));
preloadWebview
=
plus
.
webview
.
create
(
VIEW_WEBVIEW_PATH
,
String
(
id
++
));
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] preloadWebview[
${
preloadWebview
.
id
}
]`
);
}
}
return
preloadWebview
}
...
...
@@ -6311,6 +6314,9 @@ var serviceContext = (function () {
{
// 创建预加载
const
preloadWebview
=
createPreloadWebview
();
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`navigateFinish.preloadWebview:
${
preloadWebview
.
id
}
`
);
}
if
(
!
todoNavigator
)
{
return
}
...
...
@@ -8730,6 +8736,9 @@ var serviceContext = (function () {
}
function
onWebviewReady
(
data
,
pageId
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
[uni-app] onWebviewReady.preloadWebview
'
+
(
preloadWebview
&&
preloadWebview
.
id
));
}
const
isLaunchWebview
=
pageId
===
'
1
'
;
if
(
isLaunchWebview
)
{
// 首页
setPreloadWebview
(
plus
.
webview
.
getLaunchWebview
());
...
...
@@ -8737,7 +8746,7 @@ var serviceContext = (function () {
setPreloadWebview
(
plus
.
webview
.
getWebviewById
(
pageId
));
}
if
(
preloadWebview
.
id
!==
pageId
)
{
return
console
.
error
(
`webview
[
${
pageId
}
] not found
`
)
return
console
.
error
(
`webview
Ready[
${
preloadWebview
.
id
}
][
${
pageId
}
] not match
`
)
}
preloadWebview
.
loaded
=
true
;
// 标记已 ready
...
...
@@ -8754,8 +8763,8 @@ var serviceContext = (function () {
})
}
}
}
}
const
vdSyncHandlers
=
Object
.
create
(
null
);
function
registerVdSync
(
pageId
,
callback
)
{
...
...
@@ -8778,8 +8787,8 @@ var serviceContext = (function () {
}
else
{
console
.
error
(
`vdSync[
${
pageId
}
] not found`
);
}
}
}
const
vdSyncCallbacks
=
[];
// 数据同步 callback
function
onVdSyncCallback
()
{
...
...
@@ -8788,8 +8797,8 @@ var serviceContext = (function () {
for
(
let
i
=
0
;
i
<
copies
.
length
;
i
++
)
{
copies
[
i
]();
}
}
}
function
initSubscribeHandlers
()
{
const
{
subscribe
,
...
...
@@ -9001,7 +9010,7 @@ var serviceContext = (function () {
const
handleVdData
=
{
[
UI_EVENT
]:
function
onUIEvent
(
vdBatchEvent
,
vd
)
{
vdBatchEvent
.
forEach
(([
cid
,
nid
,
event
])
=>
{
vdBatchEvent
.
forEach
(([
cid
,
nid
,
event
])
=>
{
nid
=
String
(
nid
);
console
.
log
(
`[EVENT]`
,
cid
,
nid
,
event
);
event
.
preventDefault
=
noop
;
...
...
packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
浏览文件 @
a85a6788
...
...
@@ -339,7 +339,8 @@ module.exports = function (pagesJson, userManifestJson) {
const
uniApp
=
require
(
'
../../../package.json
'
)[
'
uni-app
'
]
manifestJson
.
plus
[
'
uni-app
'
]
=
uniApp
// 控制页类型
manifestJson
.
plus
[
'
uni-app
'
].
control
=
process
.
env
.
UNI_USING_V8
?
'
v8
'
:
'
webview
'
const
control
=
process
.
env
.
UNI_USING_V3
?
'
uni-v3
'
:
(
process
.
env
.
UNI_USING_V8
?
'
v8
'
:
'
webview
'
)
manifestJson
.
plus
[
'
uni-app
'
].
control
=
control
manifestJson
.
plus
[
'
uni-app
'
].
nvueCompiler
=
appJson
.
nvueCompiler
manifestJson
.
plus
[
'
uni-app
'
].
renderer
=
appJson
.
renderer
if
(
flexDir
)
{
...
...
src/platforms/app-plus/service/framework/navigator.js
浏览文件 @
a85a6788
...
...
@@ -52,6 +52,9 @@ export function navigateFinish () {
if
(
__PLATFORM__
===
'
app-plus
'
)
{
// 创建预加载
const
preloadWebview
=
createPreloadWebview
()
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`navigateFinish.preloadWebview:
${
preloadWebview
.
id
}
`
)
}
if
(
!
todoNavigator
)
{
return
}
...
...
src/platforms/app-plus/service/framework/plugins/vdom-sync.js
浏览文件 @
a85a6788
...
...
@@ -10,14 +10,17 @@ import {
}
from
'
../../../constants
'
import
{
vdSyncCallbacks
,
removeVdSync
,
registerVdSync
}
from
'
../subscribe-handlers
'
}
from
'
../subscribe-handlers/on-vd-sync
'
import
{
vdSyncCallbacks
}
from
'
../subscribe-handlers/on-vd-sync-callback
'
const
handleVdData
=
{
[
UI_EVENT
]:
function
onUIEvent
(
vdBatchEvent
,
vd
)
{
vdBatchEvent
.
forEach
(([
cid
,
nid
,
event
])
=>
{
vdBatchEvent
.
forEach
(([
cid
,
nid
,
event
])
=>
{
nid
=
String
(
nid
)
console
.
log
(
`[EVENT]`
,
cid
,
nid
,
event
)
event
.
preventDefault
=
noop
...
...
src/platforms/app-plus/service/framework/subscribe-handlers/index.js
0 → 100644
浏览文件 @
a85a6788
import
{
VD_SYNC
,
VD_SYNC_CALLBACK
,
WEBVIEW_READY
}
from
'
../../../constants
'
import
{
registerPlusMessage
}
from
'
../plus-message
'
import
onWebviewReady
from
'
./on-webview-ready
'
import
onVdSync
from
'
./on-vd-sync
'
import
onVdSyncCallback
from
'
./on-vd-sync-callback
'
export
function
initSubscribeHandlers
()
{
const
{
subscribe
,
subscribeHandler
}
=
UniServiceJSBridge
registerPlusMessage
(
'
subscribeHandler
'
,
(
data
)
=>
{
subscribeHandler
(
data
.
type
,
data
.
data
,
data
.
pageId
)
})
// TODO 检测目标 preloadWebview 是否已准备好,因为 preloadWebview 准备好时,此处代码还没执行
subscribe
(
WEBVIEW_READY
,
onWebviewReady
)
subscribe
(
VD_SYNC
,
onVdSync
)
subscribe
(
VD_SYNC_CALLBACK
,
onVdSyncCallback
)
}
src/platforms/app-plus/service/framework/subscribe-handlers/on-vd-sync-callback.js
0 → 100644
浏览文件 @
a85a6788
export
const
vdSyncCallbacks
=
[]
// 数据同步 callback
export
default
function
onVdSyncCallback
()
{
const
copies
=
vdSyncCallbacks
.
slice
(
0
)
vdSyncCallbacks
.
length
=
0
for
(
let
i
=
0
;
i
<
copies
.
length
;
i
++
)
{
copies
[
i
]()
}
}
src/platforms/app-plus/service/framework/subscribe-handlers/on-vd-sync.js
0 → 100644
浏览文件 @
a85a6788
const
vdSyncHandlers
=
Object
.
create
(
null
)
export
function
registerVdSync
(
pageId
,
callback
)
{
(
vdSyncHandlers
[
pageId
]
||
(
vdSyncHandlers
[
pageId
]
=
[])).
push
(
callback
)
}
export
function
removeVdSync
(
pageId
)
{
delete
vdSyncHandlers
[
pageId
]
}
export
default
function
onVdSync
({
data
,
options
},
pageId
)
{
const
handlers
=
vdSyncHandlers
[
pageId
]
if
(
Array
.
isArray
(
handlers
))
{
handlers
.
forEach
(
handler
=>
{
handler
(
data
)
})
}
else
{
console
.
error
(
`vdSync[
${
pageId
}
] not found`
)
}
}
src/platforms/app-plus/service/framework/subscribe-handlers.js
→
src/platforms/app-plus/service/framework/subscribe-handlers
/on-webview-ready
.js
浏览文件 @
a85a6788
import
{
VD_SYNC
,
VD_SYNC_CALLBACK
,
WEBVIEW_READY
}
from
'
../../constants
'
import
{
preloadWebview
,
setPreloadWebview
,
consumeWebviewReady
}
from
'
./webview
'
import
{
registerPlusMessage
}
from
'
./plus-message
'
}
from
'
../webview
'
import
{
perf
}
from
'
./perf
'
}
from
'
.
.
/perf
'
function
onWebviewReady
(
data
,
pageId
)
{
export
default
function
onWebviewReady
(
data
,
pageId
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
'
[uni-app] onWebviewReady.preloadWebview
'
+
(
preloadWebview
&&
preloadWebview
.
id
))
}
const
isLaunchWebview
=
pageId
===
'
1
'
if
(
isLaunchWebview
)
{
// 首页
setPreloadWebview
(
plus
.
webview
.
getLaunchWebview
())
...
...
@@ -26,7 +19,7 @@ function onWebviewReady (data, pageId) {
setPreloadWebview
(
plus
.
webview
.
getWebviewById
(
pageId
))
}
if
(
preloadWebview
.
id
!==
pageId
)
{
return
console
.
error
(
`webview
[
${
pageId
}
] not found
`
)
return
console
.
error
(
`webview
Ready[
${
preloadWebview
.
id
}
][
${
pageId
}
] not match
`
)
}
preloadWebview
.
loaded
=
true
// 标记已 ready
...
...
@@ -43,54 +36,4 @@ function onWebviewReady (data, pageId) {
})
}
}
}
const
vdSyncHandlers
=
Object
.
create
(
null
)
export
function
registerVdSync
(
pageId
,
callback
)
{
(
vdSyncHandlers
[
pageId
]
||
(
vdSyncHandlers
[
pageId
]
=
[])).
push
(
callback
)
}
export
function
removeVdSync
(
pageId
)
{
delete
vdSyncHandlers
[
pageId
]
}
function
onVdSync
({
data
,
options
},
pageId
)
{
const
handlers
=
vdSyncHandlers
[
pageId
]
if
(
Array
.
isArray
(
handlers
))
{
handlers
.
forEach
(
handler
=>
{
handler
(
data
)
})
}
else
{
console
.
error
(
`vdSync[
${
pageId
}
] not found`
)
}
}
export
const
vdSyncCallbacks
=
[]
// 数据同步 callback
function
onVdSyncCallback
()
{
const
copies
=
vdSyncCallbacks
.
slice
(
0
)
vdSyncCallbacks
.
length
=
0
for
(
let
i
=
0
;
i
<
copies
.
length
;
i
++
)
{
copies
[
i
]()
}
}
export
function
initSubscribeHandlers
()
{
const
{
subscribe
,
subscribeHandler
}
=
UniServiceJSBridge
registerPlusMessage
(
'
subscribeHandler
'
,
(
data
)
=>
{
subscribeHandler
(
data
.
type
,
data
.
data
,
data
.
pageId
)
})
// TODO 检测目标 preloadWebview 是否已准备好,因为 preloadWebview 准备好时,此处代码还没执行
subscribe
(
WEBVIEW_READY
,
onWebviewReady
)
subscribe
(
VD_SYNC
,
onVdSync
)
subscribe
(
VD_SYNC_CALLBACK
,
onVdSyncCallback
)
}
src/platforms/app-plus/service/framework/webview/index.js
浏览文件 @
a85a6788
...
...
@@ -102,7 +102,10 @@ export function initWebview (webview, routeOptions) {
export
function
createPreloadWebview
()
{
if
(
!
preloadWebview
||
preloadWebview
.
__uniapp_route
)
{
// 不存在,或已被使用
preloadWebview
=
plus
.
webview
.
create
(
VIEW_WEBVIEW_PATH
,
String
(
id
++
))
preloadWebview
=
plus
.
webview
.
create
(
VIEW_WEBVIEW_PATH
,
String
(
id
++
))
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] preloadWebview[
${
preloadWebview
.
id
}
]`
)
}
}
return
preloadWebview
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录