update args of render method

This commit is contained in:
dntzhang 2018-11-08 08:26:38 +08:00
parent 4992ec76fd
commit 4502154dce
5 changed files with 1589 additions and 1460 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,6 @@
import { render, WeElement, tag } from '../../src/omi'
import { render, WeElement, define } from '../../src/omi'
@tag('todo-list', true)
class TodoList extends WeElement {
define('todo-list', class extends WeElement {
render(props) {
return (
<ul>
@ -11,10 +10,9 @@ class TodoList extends WeElement {
</ul>
)
}
}
})
@tag('todo-app')
class TodoApp extends WeElement {
define('todo-app', class extends WeElement {
static get data() {
return {
showList: null,
@ -25,14 +23,18 @@ class TodoApp extends WeElement {
}
}
render(props, data) {
render(props, data, store) {
return (
<div>
<h3>TODO by {data.fullName()}</h3>
{data.showList && <todo-list items={data.items} />}
<h3>TODO by {store.data.fullName()}</h3>
{store.data.showList && <todo-list items={store.data.items} />}
<form onSubmit={this.handleSubmit}>
<input id="new-todo" onChange={this.handleChange} value={data.text} />
<button>Add #{data.items.length + 1}</button>
<input
id="new-todo"
onChange={this.handleChange}
value={store.data.text}
/>
<button>Add #{store.data.items.length + 1}</button>
</form>
</div>
)
@ -72,7 +74,7 @@ class TodoApp extends WeElement {
this.store.data.showList = true
}, 12000)
}
}
})
const store = {
data: {

View File

@ -1,5 +1,5 @@
import { define } from './define'
import WeElement from './we-element'
export function tag(name, pure) {
return function(target) {
target.pure = pure

View File

@ -49,10 +49,7 @@ export default class WeElement extends HTMLElement {
}
this.host = diff(
null,
this.render(
this.props,
!this.constructor.pure && this.store ? this.store.data : this.data
),
this.render(this.props, this.data, this.store),
{},
false,
null,
@ -84,13 +81,7 @@ export default class WeElement extends HTMLElement {
update() {
this.beforeUpdate()
this.beforeRender()
diff(
this.host,
this.render(
this.props,
!this.constructor.pure && this.store ? this.store.data : this.data
)
)
diff(this.host, this.render(this.props, this.data, this.store))
this.afterUpdate()
}