Skip to content

Commit

Permalink
chore: bump version v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
geekact committed Oct 8, 2023
1 parent 9b1ca1f commit c1304a2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## v3
## [3.0.0](https://github.com/foca-js/foca/compare/v2.0.1...v3.0.0)  (2023-10-08)

### 破坏性更新

- 删除hooks函数 `useDefined`
- 删除模型`onDestroy`事件钩子
- 删除模型内`onDestroy`事件钩子
- 删除持久化`maxAge`配置

```diff
Expand Down
15 changes: 0 additions & 15 deletions docs/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,6 @@ userModel.profile(123); // 实例2缓存

---

也可以尝试一下在React组件中用`useComputed`这个hooks函数接入计算属性:

```tsx
import { FC } from 'react';
import { useComputed } from 'foca';

const App: FC = () => {
const fullName = useComputed(userModel.fullName); // string
// 这里会有TS提示你应该传几个参数,以及参数类型
const profile = useComputed(useModel.profile, 30, 'my-address'); // string

return <p>Profile: {profile}</p>;
};
```

缓存什么时候才会更新?框架自动收集依赖,只有其中某个依赖更新了,计算属性才会更新。上面的例子中,当`firstName`或者`lastName`有变化时,fullName 将被标记为`dirty`状态,下一次访问则会重新计算结果。而当`country`变化时,不影响 fullName 的结果,下一次访问仍使用缓存作为结果。

!> 可以在 computed 中使用其它 model 的数据。
Expand Down
5 changes: 5 additions & 0 deletions docs/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ const userModel = defineModel('user', {
fullName() {
return this.state.firstName + '.' + this.state.lastName;
},
profile(state, age: number) {
return this.fullName() + '-' + age;
},
},
});

const App: FC = () => {
// 只有当 firstName 或者 lastName 变化,才会重新刷新该组件
const fullName = useComputed(userModel.fullName);
// 这里会有TS提示你应该传几个参数,以及参数类型
const profile = useComputed(userModel.profile, 24);

return <div>{fullName}</div>;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "foca",
"version": "2.0.1",
"version": "3.0.0",
"repository": "[email protected]:foca-js/foca.git",
"homepage": "https://foca.js.org",
"keywords": [
Expand Down

0 comments on commit c1304a2

Please sign in to comment.