-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
97 changed files
with
30,877 additions
and
1,120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ | |
packages: | ||
- 'packages/**' | ||
- 'dev/**' | ||
- 'website' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
doc_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"text": "指南", | ||
"link": "/guide/quick-start/", | ||
"activeMatch": "/guide/" | ||
}, | ||
{ | ||
"text": "API", | ||
"link": "/api/index", | ||
"activeMatch": "/api/" | ||
}, | ||
{ | ||
"text": "博客", | ||
"link": "/blog/architecture", | ||
"activeMatch": "/blog/" | ||
}, | ||
{ | ||
"text": "常见问题", | ||
"link": "/issues/index", | ||
"activeMatch": "/issues/" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: API | ||
collapsed: false | ||
order: 4 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["index", "run", "registerApp", "loadApp", "loader", "preloadApp", "channel", "router", "setOptioins", "setExternal", "setGlobal", "clearEscapeEffect"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Garfish.channel | ||
|
||
import Highlight from '@components/Highlight'; | ||
|
||
用于应用间的通信,`Garfish.channel` 为 Garfish 的实例属性,该属性是 [EventEmitter2](https://github.com/EventEmitter2/EventEmitter2) 的实例。 | ||
|
||
### Type | ||
|
||
```ts | ||
channel: EventEmitter2; | ||
``` | ||
|
||
### 默认值 | ||
|
||
- 无 | ||
|
||
### 示例 | ||
|
||
```js | ||
// 子应用监听登录事件 | ||
const App = () => { | ||
const handleLogin = (userInfo) => { | ||
console.log(`${userInfo.name} has login`); | ||
}; | ||
|
||
useEffect(() => { | ||
window?.Garfish.channel.on('login', handleLogin); | ||
return () => { | ||
window?.Garfish.channel.removeListener('login', handleLogin); | ||
}; | ||
}); | ||
}; | ||
|
||
// 主应用触发监听事件 | ||
api.getLoginInfo().then((res) => { | ||
if (res.code === 0) { | ||
window.Garfish.channel.emit('login', res.data); | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Garfish.clearEscapeEffect | ||
|
||
用来清除逃逸沙箱的变量。 | ||
|
||
> 在微前端应用下,子应用将默认开启沙箱模式。在沙箱模式下,若发现有一些特殊的行为会逃逸沙箱系统,可以使用此方法来清除逃逸的变量; | ||
## Type | ||
```ts | ||
clearEscapeEffect: (key: string, value?: any) => void; | ||
``` | ||
|
||
## 示例 | ||
|
||
```js | ||
Garfish.clearEscapeEffect('webpackJsonp'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Garfish.getGlobalObject | ||
|
||
|
||
import Highlight from '@components/Highlight'; | ||
|
||
用于子应用获取真实 window 的值。 | ||
|
||
> 在微前端应用下,子应用将默认开启沙箱模式。在沙箱模式下,子应用中全局变量为被 proxy 的 'fakeWindow',而全局变量(真实 window)默认会被隔离。若子应用需求获取真实 window 的值,可以通过此方法获取。 | ||
|
||
|
||
:::tip | ||
1. 一般情况下我们不建议直接通过此 API 获取真实 window,这样建议的原因是: | ||
- 使用此 API 后子应用产生了一个无法独立运行的逻辑,导致子应用失去独立运行的能力; | ||
- 由于环境变量的修改并不是单向数据流,造成主应用无法感知哪些子应用会去修改 window 上的哪些变量,可能造成数据管理的混乱; | ||
|
||
2. 若需要获取真实 window 上的环境变量,可通过 [`protectVariable`](/api/run#protectvariable) 属性,将需要共享的属性放入列表中即可通过子应用的全局变量获取,这样主应用能感知到哪些值是会被修改的,哪些值是不会被修改的,能在一定程度上控制 `window` 变量的修改; | ||
|
||
::: | ||
|
||
## Type | ||
```ts | ||
getGlobalObject: () => Window & typeof globalThis; | ||
``` | ||
## 示例 | ||
|
||
```js | ||
import Garfish from 'garfish'; | ||
|
||
const nativeWindow = Garfish.getGlobalObject(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 概览 | ||
|
||
```ts | ||
import Garfish from "garfish"; | ||
``` | ||
在主应用中,我们通过 `import Garfish from "garfish";` 来引入 Garfish,并调用相关 Garfish api 去注册子应用或运行微前端应用。 | ||
|
||
其中,Garfish 是 `garfish` 包默认导出的实例,实例上包含微前端相关API,用户可以通过相应 API 完成对整个微前端应用的管理。 | ||
|
||
|
||
:::tip | ||
这里需要特殊说明的是,子应用不需要额外引入 Garfish 实例,子应用可通过 `window.Garfish` 获取全局 Garfish 实例信息,参考 [Garfish 环境变量](../guide/quickStart/env.md)。 | ||
|
||
|
||
::: | ||
|
||
|
||
## Garfish 实例方法 | ||
- [Garfish.run](/api/run) (用于初始化应用参数、启动路由监听,当路由发生变化时自动激活应用或销毁应用) | ||
- [Garfish.registerApp](/api/registerapp)(用于动态注册应用信息) | ||
- [Garfish.loadApp](/api/loadapp)(可以手动控制子应用加载和销毁) | ||
- [Garfish.router](/api/router)(提供路由跳转和路由守卫能力) | ||
- [Garfish.channel](/api/channel)(提供应用间通信的能力) | ||
- [Garfish.setExternal](/api/setexternal)(支持应用间的依赖共享) | ||
- [Garfish.getGlobalObject](/api/getglobalobject)(用于获取真实 Window) | ||
- [Garfish.setGlobalObject](/api/getglobalobject)(用于设置真实 Window 的值) | ||
- [Garfish.clearEscapeEffect](/api/getglobalobject)(用于清除逃逸的副作用) |
Oops, something went wrong.