Skip to content

Commit

Permalink
docs: local bean
Browse files Browse the repository at this point in the history
  • Loading branch information
zhennann committed Oct 3, 2024
1 parent 77efa7d commit 9b99e2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
14 changes: 6 additions & 8 deletions zova-docs/guide/essentials/ioc/anonymous-bean.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

The class decorated with `@Local` is an `anonymous bean`, so it is also called a `local bean`. This type of bean is only used within the module, there is no naming conflict, and it is easy to define and use

In [page component](../component/page.md), we created a page component `counter` through a cli command. Now, we pull out the logic of the `count` state, put it in a local bean to demonstrate the effect of logic reuse
In [page component](../component/page.md), we created a page component `counter`. Now, we pull out the logic of the `count` state, put it in a local bean to demonstrate the effect of logic reuse

## Create Local Bean: counter

The code skeleton for local bean can be created using the cli command:

```bash
$ zova :create:local page/counter/counter --module=demo-basic
```
::: tip
Context Menu - [Module Path/src/page/counter]: `Zova Create/Bean: Local`
:::

- The name of the local bean is `counter`, located in the directory `page/counter`
Enter the name of local bean according to the prompt, such as `counter`. The VSCode extension will automatically add the code skeleton of `local bean`

`src/suite/a-demo/modules/demo-basic/src/page/counter/counter.ts`

Expand Down Expand Up @@ -69,7 +67,7 @@ export class RenderCounter {
render() {
return (
<div>
<div>count(ref): {this.$$counter.count}</div>
<div>{this.$$counter.count}</div>
<button onClick={() => this.$$counter.increment()}>Increment</button>
<button onClick={() => this.$$counter.decrement()}>Decrement</button>
</div>
Expand Down
14 changes: 6 additions & 8 deletions zova-docs/zh/guide/essentials/ioc/anonymous-bean.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

使用`@Local`装饰的 class 就是`匿名bean`,因此也称之为`local bean`。此类 bean 仅在模块内部使用,不存在命名冲突的问题,定义和使用都很便捷

[页面组件](../component/page.md)中,我们通过一个 cli 命令创建了一个页面组件`counter`。现在,我们把其中关于 count 状态的逻辑抽离出来,放入一个 local bean 当中,演示逻辑复用的效果
[页面组件](../component/page.md)中,我们创建了一个页面组件`counter`。现在,把其中关于 count 状态的逻辑抽离出来,放入一个 local bean 当中,演示逻辑复用的效果

## 创建Local Bean: counter

可以通过 cli 命令创建 local bean 的代码骨架:

```bash
$ zova :create:local page/counter/counter --module=demo-basic
```
::: tip
右键菜单 - [模块路径/src/page/counter]: `Zova Create/Bean: Local`
:::

- local bean 的名称是`counter`,位于目录`page/counter`中,也就是放入页面组件`counter`所在的目录
依据提示输入 local bean 的名称,比如`counter`,VSCode 插件会自动添加 local bean 的代码骨架

`src/suite/a-demo/modules/demo-basic/src/page/counter/counter.ts`

Expand Down Expand Up @@ -69,7 +67,7 @@ export class RenderCounter {
render() {
return (
<div>
<div>count(ref): {this.$$counter.count}</div>
<div>{this.$$counter.count}</div>
<button onClick={() => this.$$counter.increment()}>Increment</button>
<button onClick={() => this.$$counter.decrement()}>Decrement</button>
</div>
Expand Down

0 comments on commit 9b99e2a

Please sign in to comment.