-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from zhangfisher/master
docs: update docs site
- Loading branch information
Showing
40 changed files
with
1,042 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'dumi'; | ||
|
||
export default defineConfig({ | ||
outputPath: 'docs-dist', | ||
themeConfig: { | ||
name: 'Helux', | ||
}, | ||
}); |
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,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,3 @@ | ||
module.exports = { | ||
extends: require.resolve('@umijs/lint/dist/config/eslint'), | ||
}; |
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,6 @@ | ||
import { defineConfig } from 'father'; | ||
|
||
export default defineConfig({ | ||
// more father config: https://github.com/umijs/father/blob/master/docs/config.md | ||
esm: { output: 'dist' }, | ||
}); |
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,6 @@ | ||
node_modules | ||
/dist | ||
.dumi/tmp | ||
.dumi/tmp-test | ||
.dumi/tmp-production | ||
.DS_Store |
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,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx commitlint --edit "${1}" |
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,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
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,2 @@ | ||
/dist | ||
*.yaml |
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,19 @@ | ||
module.exports = { | ||
pluginSearchDirs: false, | ||
plugins: [ | ||
require.resolve('prettier-plugin-organize-imports'), | ||
require.resolve('prettier-plugin-packagejson'), | ||
], | ||
printWidth: 80, | ||
proseWrap: 'never', | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
overrides: [ | ||
{ | ||
files: '*.md', | ||
options: { | ||
proseWrap: 'preserve', | ||
}, | ||
}, | ||
], | ||
}; |
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,3 @@ | ||
{ | ||
"extends": "@umijs/lint/dist/config/stylelint" | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# helux-docs | ||
|
||
[![NPM version](https://img.shields.io/npm/v/helux-docs.svg?style=flat)](https://npmjs.org/package/helux-docs) | ||
[![NPM downloads](http://img.shields.io/npm/dm/helux-docs.svg?style=flat)](https://npmjs.org/package/helux-docs) | ||
|
||
A state library that integrates atom, signal, derive, watch and collection dep | ||
|
||
## Usage | ||
|
||
TODO | ||
|
||
## Options | ||
|
||
TODO | ||
|
||
## Development | ||
|
||
```bash | ||
# install dependencies | ||
$ pnpm install | ||
|
||
# develop library by docs demo | ||
$ pnpm start | ||
|
||
# build library source code | ||
$ pnpm run build | ||
|
||
# build library source code in watch mode | ||
$ pnpm run build:watch | ||
|
||
# build docs | ||
$ pnpm run docs:build | ||
|
||
# check your project for potential problems | ||
$ pnpm run doctor | ||
``` | ||
|
||
## LICENSE | ||
|
||
MIT |
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,12 @@ | ||
--- | ||
nav: | ||
title: 生态 | ||
order: 3 | ||
--- | ||
# 生态 | ||
|
||
|
||
|
||
|
||
|
||
|
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,12 @@ | ||
--- | ||
|
||
nav: | ||
title: 教程 | ||
order: 2 | ||
--- | ||
|
||
# 教程 | ||
|
||
|
||
|
||
|
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,44 @@ | ||
--- | ||
group: | ||
title: 基础 | ||
order: 1 | ||
order: 1 | ||
--- | ||
|
||
# 事件 | ||
|
||
|
||
内部提供事件总线让用户可以全局使用 | ||
|
||
### 发射事件 | ||
|
||
```ts | ||
import { emit } from 'helux'; | ||
|
||
emit('xxx_event', 1, 2, 3); | ||
``` | ||
|
||
### 组件外监听事件 | ||
|
||
```ts | ||
import { on } from 'helux'; | ||
|
||
const off = on('xxx_event', (...args) => { | ||
console.log('received args ', args); | ||
}); | ||
off(); // 取消监听 | ||
``` | ||
|
||
### 组件内监听事件 | ||
|
||
组件内使用 `useOnEvent` 钩子函数监听,再组件销毁后会自动取消监听 | ||
|
||
```tsx | ||
import { useOnEvent } from 'helux'; | ||
|
||
function Demo() { | ||
useOnEvent('xxx_event', (...args) => { | ||
console.log('received args ', args); | ||
}); | ||
} | ||
``` |
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,8 @@ | ||
--- | ||
group: | ||
title: 开始 | ||
order: 0 | ||
order: 2 | ||
--- | ||
|
||
# 更新历史 |
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,23 @@ | ||
--- | ||
|
||
nav: | ||
title: 指南 | ||
order: 0 | ||
|
||
--- | ||
|
||
# 指南 | ||
|
||
`helux` 是一个集`atom`、`signal`、`依赖收集`为一体的 `react`状态库,相比`recoil`和`jotai`,它拥有以下优势 | ||
|
||
- 基于最快的不可变 js 库[limu](https://github.com/tnfe/limu)开发,拥有超强性能 | ||
- `atom`支持依赖收集,意味着`atom`不用拆分的很细,`atom` 就可以等同于 `model`,天然对 `DDD` 领域驱动设计友好 | ||
- 内置 `signal` 响应机制,可直接将共享对象的值交给 signal 或 block 视图与数据关系的绑定,实现 0 hook 编码,实现 dom 粒度的更新 | ||
- 内置 `loading` 模块,可对所有异步任务做运行状态、错误捕捉做管理 | ||
- 支持可变派生,当共享对象 a 的发生变化后需要自动引起共享状态 b 的某些节点变化时,可定义 mutate 函数来完成这种变化的连锁反应关系,对数据做最小粒度的更新 | ||
- 支持全量派生,不需要对数据做细粒度更新时使用全量派生更合适 | ||
- 全量派生、可变派生均支持异步任务 | ||
- 全量派生、可变派生除数据变更驱动执行外,还支持人工重新触发运行 | ||
- 内置事件系统 | ||
- 支持中间件、插件系统,可无缝对接 redux 生态相关工具库 | ||
- 100% ts 编码,类型提示优化 |
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,9 @@ | ||
--- | ||
group: | ||
title: 开始 | ||
order: 0 | ||
order: 1 | ||
--- | ||
|
||
# 安装 | ||
|
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,24 @@ | ||
--- | ||
group: | ||
title: 基础 | ||
order: 0 | ||
order: 1 | ||
--- | ||
|
||
# 加载状态 | ||
|
||
|
||
可使用 `getMutateLoading` 、 `getActionLoading` 、`getDeriveLoading` 获取相对于的 loading 状态 | ||
|
||
```ts | ||
import { getMutateLoading, getActionLoading, getDeriveLoading } from 'helux'; | ||
|
||
// loading.xxx 获取某个 mutate 函数的具体 loading 状态 | ||
const loading = getMutateLoading(someShared); | ||
|
||
// loading.xxx 获取某个 action 函数的具体 loading 状态 | ||
const loading = getActionLoading(someShared); | ||
|
||
// 获取某个全量派生结果的具体 loading 状态 | ||
const status = getDeriveLoading(someDerivedResult); | ||
``` |
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,28 @@ | ||
--- | ||
group: | ||
title: 基础 | ||
order: 0 | ||
order: 1 | ||
--- | ||
|
||
# 中间件 | ||
中间件是一个同步函数,在状态提交前被调用,可通过中间件函做一些统一操作,例如数修改草稿的时间属性 | ||
|
||
### 定义中间件 | ||
|
||
```ts | ||
import { Middleware } from 'helux'; | ||
|
||
const markTimeMiddleWare: Middleware = (params) => { | ||
const { sharedKey, moduleName, draft } = params; | ||
draft.time = Date.now(); | ||
}; | ||
``` | ||
|
||
### 使用中间件 | ||
|
||
```ts | ||
import { addMiddleware } from 'helux'; | ||
|
||
addMiddleware(markTimeMiddleWare); | ||
``` |
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,60 @@ | ||
--- | ||
group: | ||
title: 基础 | ||
order: 0 | ||
order: 1 | ||
--- | ||
|
||
# 模型 - model | ||
|
||
|
||
提供 `model` 函数,帮助用户按业务功能聚合管理相关状态与操作 | ||
|
||
```ts | ||
const model = createModel((api) => { | ||
// api对象 有详细的类型提示 | ||
const userCtx = api.shareState({ a: 1, b: 2 }); | ||
const { state, setState } = userCtx; | ||
const someResult = api.deriveAtom(() => state.a + 100); | ||
|
||
function changeA() { | ||
setState((draft) => { | ||
draft.a += 1; | ||
}); | ||
} | ||
|
||
return { | ||
changeA, | ||
state, | ||
someResult, | ||
setState, | ||
}; | ||
}); | ||
``` | ||
|
||
## modelFactory | ||
|
||
提供更高阶的 `modelFactory` 函数,帮助用户创建可克隆使用的 model 工厂函数,做到逻辑复用但状态隔离的效果 | ||
|
||
```ts | ||
const factory = modelFactory((api, extra) => { | ||
const userCtx = api.shareState({ a: 1, b: 2 }, { moduleName: extra }); | ||
const { state, setState } = userCtx; | ||
const someResult = api.deriveAtom(() => state.a + 100); | ||
|
||
function changeA() { | ||
setState((draft) => { | ||
draft.a += 1; | ||
}); | ||
} | ||
|
||
return { | ||
changeA, | ||
state, | ||
someResult, | ||
setState, | ||
}; | ||
}); | ||
const model1 = factory.build('Model1'); | ||
const model2 = factory.build('Model2'); | ||
``` |
Oops, something went wrong.