Skip to content

Commit

Permalink
feat(1.0.0-beta.7): add app state of before_mount
Browse files Browse the repository at this point in the history
  • Loading branch information
bailicangdu committed Sep 18, 2023
1 parent c5f18b7 commit 9133229
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
13 changes: 7 additions & 6 deletions dev/main-react16/src/pages/vite2/vite2.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function vite2 (props) {
microApp.router.push({name: 'vite2', path: '/micro-app/vite2/'})
}

function jumpToPage2 () {
function jumpToElementPlus () {
microApp.router.push({name: 'vite2', path: '/micro-app/vite2/element-plus'})
}

function jumpToPage3 () {
function jumpToAntDesignVue () {
microApp.router.push({name: 'vite2', path: '/micro-app/vite2/ant-design-vue'})
}

Expand Down Expand Up @@ -80,8 +80,8 @@ function vite2 (props) {
向子应用发送数据
</Button>
<Button type="primary" onClick={jumpToHome}>控制子应用跳转首页</Button>
<Button type="primary" onClick={jumpToPage2}>控制子应用跳转element-plus</Button>
<Button type="primary" onClick={jumpToPage3}>控制子应用跳转ant-design-vue</Button>
<Button type="primary" onClick={jumpToElementPlus}>控制子应用跳转element-plus</Button>
<Button type="primary" onClick={jumpToAntDesignVue}>控制子应用跳转ant-design-vue</Button>
</Col>
</div>
{
Expand All @@ -92,7 +92,8 @@ function vite2 (props) {
url={`${config.vite2}micro-app/vite2/`}
// url={`http://127.0.0.1:8080/micro-app/vite2/`}
data={data}
// onBeforemount={() => hideLoading(false)}
onCreated={() => Promise.resolve().then(() => jumpToElementPlus())}
// onBeforemount={() => jumpToElementPlus()}
onMounted={handleMounted}
onDataChange={handleDataChange}
onAfterhidden={() => console.log('基座:keep-alive:Afterhidden 已推入后台')}
Expand All @@ -103,7 +104,7 @@ function vite2 (props) {
// inline
// disableSandbox
iframe
keep-router-state
// keep-router-state
// disable-patch-request
// keep-alive
// default-page='/micro-app/vite2/page2'
Expand Down
5 changes: 5 additions & 0 deletions docs/1.x/zh-cn/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

`2023-09-19`

- **New**

- 🆕 新增了子应用内部状态`before_mount`,用于标记子应用在资源加载后和执行js前的中间状态。

- **Bug Fix**

- 🐞 修复了在iframe模式下,子应用使用`monaco-editor`时代码输入框光标失效的问题。
- 🐞 修复了在`window.mount`为Promise时抛出的错误无法捕获的问题。
- 🐞 修复了在iframe模式下,子应用加载完成之前进行导航导致报错的问题。

- **Update**

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
__TEST__: true,
'ts-jest': {
tsconfig: {
target: 'es5',
target: 'ES2017',
noUnusedLocals: true,
strictNullChecks: true,
noUnusedParameters: true,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/create_app.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable promise/param-names */
import { commonStartEffect, releaseAllEffect, ports } from './common/initial'
import { appInstanceMap } from '../create_app'
import { appStates, keepAliveStates } from '../libs/constants'
import { appStates, keepAliveStates } from '../constants'
import microApp, { unmountApp, unmountAllApps, getActiveApps } from '..'

describe('create_app', () => {
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum appStates {
CREATED = 'created',
LOADING = 'loading',
LOAD_FAILED = 'load_failed',
BEFORE_MOUNT = 'before_mount',
MOUNTING = 'mounting',
MOUNTED = 'mounted',
UNMOUNT = 'unmount',
Expand Down
2 changes: 2 additions & 0 deletions src/create_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export default class CreateApp implements AppInterface {
this.fiber = fiber
this.routerMode = routerMode

this.setAppState(appStates.BEFORE_MOUNT)

const dispatchBeforeMount = () => dispatchLifecyclesEvent(
this.container!,
this.name,
Expand Down
1 change: 1 addition & 0 deletions src/sandbox/router/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function createRouterApi (): RouterApi {
* TODO: 子应用开始渲染但是还没渲染完成
* 1、调用跳转改如何处理
* 2、iframe的沙箱还没初始化时执行跳转报错,如何处理。。。
* 3、hidden app 是否支持跳转
*/
if (getActiveApps({ excludeHiddenApp: true, excludePreRender: true }).includes(appName)) {
const app = appInstanceMap.get(appName)!
Expand Down

0 comments on commit 9133229

Please sign in to comment.