Skip to content

Commit

Permalink
docs: migrate doc to rspress (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw authored Nov 1, 2024
1 parent 1fd8112 commit 32647e2
Show file tree
Hide file tree
Showing 97 changed files with 30,877 additions and 1,120 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ es/
.rts2_cache/
.yarn/
temp/
/docs
/
# .npmrc
**/.angular
.wireit
Expand Down Expand Up @@ -39,8 +39,6 @@ lerna-debug.log


# use pnpm ignore lock files
package-lock.json
yarn.lock
**/package-lock.json
**/yarn.lock
.wireit
6,145 changes: 5,035 additions & 1,110 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
packages:
- 'packages/**'
- 'dev/**'
- 'website'
25 changes: 25 additions & 0 deletions website-new/.gitignore
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
22 changes: 22 additions & 0 deletions website-new/docs/_meta.json
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/"
}
]
5 changes: 5 additions & 0 deletions website-new/docs/api/__meta__.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: API
collapsed: false
order: 4
---
1 change: 1 addition & 0 deletions website-new/docs/api/_meta.json
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"]
40 changes: 40 additions & 0 deletions website-new/docs/api/channel.mdx
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);
}
});
```
16 changes: 16 additions & 0 deletions website-new/docs/api/clearEscapeEffect.md
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');
```
31 changes: 31 additions & 0 deletions website-new/docs/api/getGlobal.mdx
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();
```
27 changes: 27 additions & 0 deletions website-new/docs/api/index.md
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)(用于清除逃逸的副作用)
Loading

0 comments on commit 32647e2

Please sign in to comment.