Releases: Tencent/omi
Releases · Tencent/omi
v4.0.24
v4.0.23
- [Update] change the args of render method
before:
render(props, data) {
//data === this.store.data when using store system
return (
<h1 onClick={this.onClick}>Hello, {data.name}!</h1>
)
}
after:
render(props, data, store) {
return (
<h1 onClick={this.onClick}>Hello, {store.data.name}!</h1>
)
}
v4.0.22
v4.0.21
noSlot support and fix render array
noSlot
For writing OMI plugins, noSlot is very useful. He will not insert redundant DOM into HTML and you can get the vdom in the plugin by props.children.
import { define, render, WeElement } from 'omi'
define('fancy-tabs', class extends WeElement {
static noSlot = true
render() {
return [
<div id="tabs">
<slot id="tabsSlot" name="title" />
</div>,
<div id="panels">
<slot id="panelsSlot" />
</div>,
<div>Show me only when noSlot is true!</div>
]
}
})
define('my-app', class extends WeElement {
render() {
return (
<div>
<fancy-tabs>
<button slot="title">Title</button>
<button slot="title" selected>
Title 2
</button>
<button slot="title">Title 3</button>
<section>content panel 1</section>
<section>content panel 2</section>
<section>content panel 3</section>
</fancy-tabs>
</div>
)
}
})
render(<my-app />, 'body')
defaultProps and Component support
- WeElement and Component are the same.
- Supports defaultProps
define('my-first-element', class extends WeElement {
static defaultProps = {
name: 'Omi',
myAge: 18
}
render(props) {
return (
<h1>Hello, {props.name}! Age {props.myAge}</h1>
)
}
})
Supports useCss in pure function element
v4.0.18 omi v4.0.18 - supports useCss
Add props and data args in pure element.
define('todo-list', function(props, data) {
return (
<ul>
{props.items.map(item => (
<li key={item.id}>{item.text}</li>
))}
</ul>
)
})
Simple checking for updating of observe element
https://github.com/Tencent/omi/blob/master/packages/omi/src/observe.js#L14-L20
It should be noted that if observe
is used, do not set the value of data in some of the following functions: some complex objects such as obj or arr:
- render
- beforeRender
- beforeUpdate
- afterUpdate
Because data settings will simply compare the value before and after, complex objects will not be deep contrast, the contrast value will trigger different update, update will trigger the above function, infinite recursion.
But you set the property of data as a simple value type(string, number, bool ...)in those functions.
useData support
import { define, render } from 'omi'
define('my-counter', function() {
const [count, setCount] = this.useData(0)
return (
<div>
<button onClick={() => setCount(count - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(count + 1)}>+</button>
</div>
)
})
render(<my-counter />, 'body')