omis - update counter demo and omis docs

This commit is contained in:
dntzhang 2019-07-21 20:37:10 +08:00
parent 58eda8dfbd
commit 7e73749b6a
6 changed files with 81 additions and 6 deletions

View File

@ -9,6 +9,44 @@
* 每个组件的 store 可以依赖全局 store中心化
* 每个组件 store 拥有 update 方法,执行该方法自定局部刷新组件
## 快速入门
```jsx
import { render } from 'omis'
const Counter = (props, store) => {
return (
<div>
<button onClick={store.sub}>-</button>
<span>{store.count}</span>
<button onClick={store.add}>+</button>
</div>
)
}
Counter.store = _ => {
return {
count: 1,
add(e) {
this.count++
this.update()
},
sub() {
this.count--
this.update()
}
}
}
Counter.css = `
span{
color: red;
}
`
render(<Counter />, 'body')
```
## 开发
``` bash

View File

@ -9,6 +9,43 @@
* Stores of each component can rely on global stores and be centralized
* Each component store has an update method that executes the method to customize local refresh components
## Usage
```jsx
import { render } from 'omis'
const Counter = (props, store) => {
return (
<div>
<button onClick={store.sub}>-</button>
<span>{store.count}</span>
<button onClick={store.add}>+</button>
</div>
)
}
Counter.store = _ => {
return {
count: 1,
add(e) {
this.count++
this.update()
},
sub() {
this.count--
this.update()
}
}
}
Counter.css = `
span{
color: red;
}
`
render(<Counter />, 'body')
```
## Develop

View File

@ -5,7 +5,7 @@ const Counter = (props, store) => {
return (
<div>
<button onClick={store.sub}>-</button>
<text>{store.count}</text>
<span>{store.count}</span>
<button onClick={store.add}>+</button>
</div>
)

View File

@ -5,7 +5,7 @@ const Counter = (props, store) => {
return (
<div>
<button onClick={store.sub}>-</button>
<text>{store.count}</text>
<span>{store.count}</span>
<button onClick={store.add}>+</button>
</div>
)

View File

@ -18,7 +18,7 @@ const Counter = (props, store) => {
return (
<div>
<button onClick={store.sub}>-</button>
<text>{store.count}</text>
<span>{store.count}</span>
<button onClick={store.add}>+</button>
</div>
)
@ -50,7 +50,7 @@ const Counter = (props, store) => {
return (
h('div', {}, [
h('button', { onClick: store.sub }, '-'),
h('text', {}, store.count),
h('span', {}, store.count),
h('button', { onClick: store.add }, '+')
])
)

View File

@ -18,7 +18,7 @@ const Counter = (props, store) => {
return (
<div>
<button onClick={store.sub}>-</button>
<text>{store.count}</text>
<span>{store.count}</span>
<button onClick={store.add}>+</button>
</div>
)
@ -50,7 +50,7 @@ const Counter = (props, store) => {
return (
h('div', {}, [
h('button', { onClick: store.sub }, '-'),
h('text', {}, store.count),
h('span', {}, store.count),
h('button', { onClick: store.add }, '+')
])
)