Skip to content

Commit

Permalink
chore: format doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Jan 4, 2024
1 parent 46bf5c7 commit a4d659d
Show file tree
Hide file tree
Showing 241 changed files with 836 additions and 654 deletions.
1 change: 1 addition & 0 deletions docs-src/docs/api/atom-ctx/flush.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ order: 9
功能同顶层 api `flush`,自动绑定了目标共享状态,调用时无需再绑定。

---

:::info
更多用法查阅[API/工具/flush](/api/utils/flush)
:::
1 change: 1 addition & 0 deletions docs-src/docs/api/atom-ctx/get-action-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ order: 4
功能同顶层 api `getActionLoading`,自动绑定了目标共享状态,调用时无需再绑定。

---

:::info
更多用法查阅[API/工具/getActionLoading](/api/utils/get-action-loading)
:::
1 change: 1 addition & 0 deletions docs-src/docs/api/atom-ctx/get-mutate-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ order: 5
功能同顶层 api `getMutateLoading`,自动绑定了目标共享状态,调用时无需再绑定。

---

:::info
更多用法查阅[API/工具/getMutateLoading](/api/utils/get-mutate-loading)
:::
1 change: 1 addition & 0 deletions docs-src/docs/api/atom-ctx/reactive-desc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ order: 8
功能同顶层 api `reactiveDesc`,自动绑定了目标共享状态,调用时无需再绑定。

---

:::info
更多用法查阅[API/工具/reactiveDesc](/api/utils/reactive-desc)
:::
1 change: 1 addition & 0 deletions docs-src/docs/api/atom-ctx/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ order: 7
功能同顶层 api`sync`,自动绑定了目标共享状态,调用时无需再绑定。

---

:::info
更多用法查阅[API/基础/sync](/api/base/sync)
:::
6 changes: 4 additions & 2 deletions docs-src/docs/api/atom-ctx/use-action-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ order: 5
# useActionLoading

组件中使用`action`函数的执行状态
___

---

:::info
和顶层api[Hooks/useActionLoading](/api/hooks/use-action-loading) 使用方式保持一致,区别是内部自动绑定了当前共享状态
和顶层 api[Hooks/useActionLoading](/api/hooks/use-action-loading) 使用方式保持一致,区别是内部自动绑定了当前共享状态
:::
5 changes: 3 additions & 2 deletions docs-src/docs/api/atom-ctx/use-force-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ order: 2

强制更新订阅了某个节点变化的所有组件实例

___
---

:::info
和顶层api[Hooks/useGlobalForceUpdate](/api/hooks/use-global-force-update) 使用方式保持一致,区别是内部自动绑定了当前共享状态
和顶层 api[Hooks/useGlobalForceUpdate](/api/hooks/use-global-force-update) 使用方式保持一致,区别是内部自动绑定了当前共享状态
:::
5 changes: 3 additions & 2 deletions docs-src/docs/api/atom-ctx/use-local-force-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ order: 4

强制更新当前组件实例

___
---

:::info
和顶层api[Hooks/useLocalForceUpdate](/api/hooks/use-local-force-update) 保持一致
和顶层 api[Hooks/useLocalForceUpdate](/api/hooks/use-local-force-update) 保持一致
:::
7 changes: 4 additions & 3 deletions docs-src/docs/api/atom-ctx/use-local-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ order: 3

使用本地状态

___
---

:::info
和顶层api[Hooks/useMutable](/api/hooks/use-mutable) 保持一致
:::
和顶层 api[Hooks/useMutable](/api/hooks/use-mutable) 保持一致
:::
5 changes: 3 additions & 2 deletions docs-src/docs/api/atom-ctx/use-mutate-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ order: 6

组件中使用`mutate`函数的执行状态

___
---

:::info
和顶层api[Hooks/useMutateLoading](/api/hooks/use-mutate-loading) 使用方式保持一致,区别是内部自动绑定了当前共享状态
和顶层 api[Hooks/useMutateLoading](/api/hooks/use-mutate-loading) 使用方式保持一致,区别是内部自动绑定了当前共享状态
:::
6 changes: 4 additions & 2 deletions docs-src/docs/api/atom-ctx/use-reactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ order: 7
# useReactive

组件中使用`reactive`响应式状态
___

---

:::info
和顶层api[Hooks/useReactive](/api/hooks/use-reactive) 使用方式保持一致,区别是内部自动绑定了当前共享状态
和顶层 api[Hooks/useReactive](/api/hooks/use-reactive) 使用方式保持一致,区别是内部自动绑定了当前共享状态
:::
2 changes: 1 addition & 1 deletion docs-src/docs/api/atom-ctx/use-state-x.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ order: 1
功能同顶层 api`useAtomX`,自动绑定了目标共享状态,调用时无需再绑定。

---

:::info
更多用法查阅[Hooks/useAtomX](/api/hooks/use-atom-x)
:::

1 change: 1 addition & 0 deletions docs-src/docs/api/atom-ctx/use-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ order: 0
功能同顶层 api`useAtom`,自动绑定了目标共享状态,调用时无需再绑定。

---

:::info
更多用法查阅[Hooks/useAtom](/api/hooks/use-atom)
:::
10 changes: 4 additions & 6 deletions docs-src/docs/api/base/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ order: 0

## 基础用法

### 创建同步action
### 创建同步 action

```ts
import { share, action } from 'helux';

const { state } = sharex({a:1, b:2});
const { state } = sharex({ a: 1, b: 2 });

const hiAction = action(state)()(({ draft, payload }) => {
draft.a += 100;
Expand All @@ -37,9 +37,9 @@ const hiAction = action(state)<[number, string]>()(({ draft, payload }) => {
}, 'hiAction');
```

### 创建异步action
### 创建异步 action

和创建同步action方式一样,只需将函数声明为异步函数即可,草稿变更后,会在下一次事件循环的微任务开始前提交变更数据
和创建同步 action 方式一样,只需将函数声明为异步函数即可,草稿变更后,会在下一次事件循环的微任务开始前提交变更数据

```ts
const delay = (ms = 1000) => new Promise((r) => setTimeout(r, ms));
Expand All @@ -50,5 +50,3 @@ const hiAsyncAction = action(state)()(async ({ draft, payload }) => {
draft.a += 100;
}, 'hiAsyncAction');
```


10 changes: 6 additions & 4 deletions docs-src/docs/api/hooks/use-action-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ order: 8
类型描述为

```ts
function useActionLoading<T = SharedState>(target?: T): [
function useActionLoading<T = SharedState>(
target?: T,
): [
SafeLoading, // 获取各个 action desc 的运行状态
SetState<LoadingState>, // 人工修改执行状态(大多数时候都不需要用到此功能)
IInsRenderInfo,
Expand All @@ -26,11 +28,11 @@ function useActionLoading<T = SharedState>(target?: T): [
/**
* defaultShowCode: true
*/
import { share, useAtom, useActionLoading } from 'helux';
import { share, useActionLoading, useAtom } from 'helux';

const [dictAtom, , ctx] = share({ a: 1, b: { b1: 1 } });
const delay = (ms = 1000) => new Promise((r) => setTimeout(r, ms));
const changeA = ctx.action()(async ({draft})=>{
const changeA = ctx.action()(async ({ draft }) => {
await delay(1000);
draft.a += 1;
}, 'changeA'); // 定好 action 描述为 changeA
Expand All @@ -41,7 +43,7 @@ export default function () {
const [dict, setDict] = useAtom(dictAtom);

// or: ctx.useActionLoading();
const [ ld ] = useActionLoading(dictAtom);
const [ld] = useActionLoading(dictAtom);
return (
<div>
{ld.changeA.ok && <h1>{dict.a}</h1>}
Expand Down
30 changes: 20 additions & 10 deletions docs-src/docs/api/hooks/use-global-force-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ function Demo() {
);
}

export default ()=> <><Demo /><Demo /></>;
export default () => (
<>
<Demo />
<Demo />
</>
);
```

### 指定更新范围

:::info
由于指定了更新范围`state.a`下述例子中Demo2因未使用到`state.a`将不被更新
由于指定了更新范围`state.a`下述例子中 Demo2 因未使用到`state.a`将不被更新
:::

```tsx
Expand All @@ -69,7 +74,7 @@ const [dictAtom, , ctx] = share({ a: 1, b: { b1: 2 } });
function Demo1() {
// 或写为
// or const updateSomeIns = ctx.useForceUpdate(state=>[state.a]);
const updateSomeIns = useGlobalForceUpdate(dictAtom, state=>[state.a]);
const updateSomeIns = useGlobalForceUpdate(dictAtom, (state) => [state.a]);
const [dict] = useAtom(dictAtom);
return (
<div>
Expand All @@ -81,7 +86,7 @@ function Demo1() {
}

function Demo2() {
const updateSomeIns = useGlobalForceUpdate(dictAtom, state=>[state.a]);
const updateSomeIns = useGlobalForceUpdate(dictAtom, (state) => [state.a]);
const [dict] = useAtom(dictAtom);
return (
<div>
Expand All @@ -92,22 +97,27 @@ function Demo2() {
);
}

export default ()=> <><Demo1 /><Demo2 /></>;
export default () => (
<>
<Demo1 />
<Demo2 />
</>
);
```

### 重写更新范围

支持调用时重写更新范围

```ts
updateSomeAtomIns(state=>[state.c]); // 本次更新只更新 c 相关的实例
updateSomeAtomIns((state) => [state.c]); // 本次更新只更新 c 相关的实例

// 重写为 null,表示更新所有实例,强制覆盖可能存在的 presetDeps
updateSomeAtomIns(null)
updateSomeAtomIns(null);

// 返回空数组不会做任何更新
updateSomeAtomIns(state=>[]);
updateSomeAtomIns((state) => []);

// 返回里包含了自身也会触发更新所有实例
updateSomeAtomIns(state=>[state]);
```
updateSomeAtomIns((state) => [state]);
```
21 changes: 12 additions & 9 deletions docs-src/docs/api/hooks/use-global-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ order: 5

# useGlobalId

使用全局id,配合`ICreationAtomOptions.rules`里的`globalIds`参数,满足条件时被触发刷新
使用全局 id,配合`ICreationAtomOptions.rules`里的`globalIds`参数,满足条件时被触发刷新

:::tip
更新`rules`配置可阅读[rules](/api/base/atom#rules)了解
Expand All @@ -16,16 +16,19 @@ order: 5
/**
* defaultShowCode: true
*/
import React from 'react';
import { atomx, useGlobalId } from 'helux';

const { state, reactive, getSnap } = atomx({a:1, b:1}, {
rules: [
{
when: state=>state.a, globalIds: ['up1'],
},
]
});
const { state, reactive, getSnap } = atomx(
{ a: 1, b: 1 },
{
rules: [
{
when: (state) => state.a,
globalIds: ['up1'],
},
],
},
);
const change = () => {
reactive.a += 1;
};
Expand Down
2 changes: 0 additions & 2 deletions docs-src/docs/api/hooks/use-local-force-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ order: 9
/**
* defaultShowCode: true
*/
import React from 'react';
import { useLocalForceUpdate } from 'helux';


export default function () {
const forceUpdate = useLocalForceUpdate();

Expand Down
15 changes: 9 additions & 6 deletions docs-src/docs/api/hooks/use-mutable.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ order: 6
/**
* defaultShowCode: true
*/
import React from 'react';
import { useMutable } from 'helux';

export default function Demo() {
const [obj, setObj] = useMutable({ a:1, b: {b1:1} });
const change = ()=>{
setObj(draft=>{
draft.b.b1+=100;
const [obj, setObj] = useMutable({ a: 1, b: { b1: 1 } });
const change = () => {
setObj((draft) => {
draft.b.b1 += 100;
});
};

return <h1><button onClick={change}>obj.b.b1 {obj.b.b1}</button></h1>;
return (
<h1>
<button onClick={change}>obj.b.b1 {obj.b.b1}</button>
</h1>
);
}
```
19 changes: 11 additions & 8 deletions docs-src/docs/api/hooks/use-mutate-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ order: 8
类型描述为

```ts
function useMutateLoading<T = SharedState>(target?: T): [
SafeLoading, // 获取各个 mutate desc 的运行状态
function useMutateLoading<T = SharedState>(
target?: T,
): [
SafeLoading, // 获取各个 mutate desc 的运行状态
SetState<LoadingState>, // 人工修改执行状态(大多数时候都不需要用到此功能)
IInsRenderInfo,
];
```

___
---

:::info
此函数偏向于提供给库开发者,推荐阅读[模块化/defineMutateDerive](/guide/modular#definemutatederive)了解和使用配套生成的`useLoading`会更方便
:::
Expand All @@ -32,16 +35,16 @@ import { share, useAtom, useMutateLoading } from 'helux';
const [dictAtom, , ctx] = share({ a: 1, b: { b1: 1 } }, { moduleName: 'uml' });
const delay = (ms = 1000) => new Promise((r) => setTimeout(r, ms));
const witness = ctx.mutate({
deps: ()=>[dictAtom.b.b1],
task: async ({draft, input})=>{
deps: () => [dictAtom.b.b1],
task: async ({ draft, input }) => {
await delay(1000);
draft.a += input[0];
},
immediate: true,
desc: 'changeA',
});
const changeB1 = ()=>{
ctx.setDraft(draft=> draft.b.b1+=1);
const changeB1 = () => {
ctx.setDraft((draft) => (draft.b.b1 += 1));
};

export default function () {
Expand All @@ -50,7 +53,7 @@ export default function () {
const [dict, setDict] = useAtom(dictAtom);

// or: ctx.useMutateLoading();
const [ ld ] = useMutateLoading(dictAtom);
const [ld] = useMutateLoading(dictAtom);

return (
<div>
Expand Down
Loading

0 comments on commit a4d659d

Please sign in to comment.