diff --git a/core/framework/src/infras/dock/page/misc.js b/core/framework/src/infras/dock/page/misc.js index aa47ac80..6267458f 100644 --- a/core/framework/src/infras/dock/page/misc.js +++ b/core/framework/src/infras/dock/page/misc.js @@ -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 diff --git a/core/framework/src/infras/runtime/listener.js b/core/framework/src/infras/runtime/listener.js index b814bb80..a0210ab6 100644 --- a/core/framework/src/infras/runtime/listener.js +++ b/core/framework/src/infras/runtime/listener.js @@ -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 diff --git a/core/framework/src/infras/styling/action.js b/core/framework/src/infras/styling/action.js index dc59958d..a2f25cd6 100644 --- a/core/framework/src/infras/styling/action.js +++ b/core/framework/src/infras/styling/action.js @@ -10,6 +10,7 @@ import { registerFromCssFile, getStylingDocumentId, setDocument, + removeDocument, getDocument, getDocumentNodeByRef, setElementProp, @@ -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() @@ -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) diff --git a/core/framework/test/suite/infras/runtime/interface/action.test.js b/core/framework/test/suite/infras/runtime/interface/action.test.js index 4d729e6c..e7399656 100644 --- a/core/framework/test/suite/infras/runtime/interface/action.test.js +++ b/core/framework/test/suite/infras/runtime/interface/action.test.js @@ -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 // 创建节点