Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 documentview 未随页面销毁而销毁 #676

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/framework/src/infras/dock/page/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function destroyPage(page) {

page.intent = null
page.name = null
page.doc.listener.destroyBody()
config.runtime.helper.destroyTagNode(page.doc)
page.doc = null

Expand Down
8 changes: 8 additions & 0 deletions core/framework/src/infras/runtime/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Listener {
return this.addActions(actions)
}

/**
* 发送"destroyBody"信号
*/
destroyBody(...args) {
const result = this.streamer.over(this.id, [_createAction('destroyBody', args)])
return result
}

/**
* 发送"addElement"信号
* @param node 新添加节点 可能是element或者figment
Expand Down
11 changes: 11 additions & 0 deletions core/framework/src/infras/styling/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
registerFromCssFile,
getStylingDocumentId,
setDocument,
removeDocument,
getDocument,
getDocumentNodeByRef,
setElementProp,
Expand Down Expand Up @@ -60,6 +61,10 @@ function dispatchAction(instId, actionItem) {
newActionList = sliceNewActions()
cleanNewActions()
break
case 'destroyBody':
dispatchActionForDestroyBody(newInstId, ...actionItem.args)
newActionList = [actionItem]
break
case 'addElement':
dispatchActionForAddElement(newInstId, ...actionItem.args)
newActionList = sliceNewActions()
Expand Down Expand Up @@ -134,6 +139,12 @@ function dispatchActionForCreateBody(instId, nodeHash) {
document.documentElement.appendChild(node)
}

function dispatchActionForDestroyBody(instId) {
if (getDocument(instId)) {
removeDocument(instId)
}
}

function dispatchActionForAddElement(instId, parentNodeRef, nodeHash) {
const document = getDocument(instId)
const parentNode = getDocumentNodeByRef(document, parentNodeRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ describe('action: interface 接口与数据格式', () => {
expect(callNativeMessageList[0].args[0]).to.include({ type: 'div' })
})

it('destroyBody', () => {
document.listener.destroyBody()
callNativeMessageList[0] = JSON.parse(callNativeMessageList[0])

expect(callNativeMessageList[0]).to.include({ module: 'dom', method: 'destroyBody' })
})

it('addElement', () => {
const nodeHtml = document.documentElement
// 创建节点
Expand Down