Skip to content

Commit

Permalink
fix: 修改 event 添加错误
Browse files Browse the repository at this point in the history
  • Loading branch information
marklin2012 committed Apr 9, 2020
1 parent d436e1c commit 9a45bd0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

### JSX

JSX 写起来像 html, 其实是 babel 转义成 `React.crxeateElement` 来执行的,用来构建虚拟 dom,
JSX 写起来像 html, 其实是 babel 转义成 `React.createElement` 来执行的,用来构建虚拟 dom,

```js
<h1 title="app">Yolk test</h1>
Expand Down Expand Up @@ -563,7 +563,7 @@ function updateDom(dom, preProps, nextProps) {
.forEach(name => {
if (name.slice(0, 2) === 'on') {
// onclick => chick
dom.removeEventListener(name.slice(0, 2).toLowerCase(), preProps[name], false)
dom.removeEventListener(name.slice(2).toLowerCase(), preProps[name], false)
} else {
dom[name] = ''
}
Expand All @@ -574,7 +574,7 @@ function updateDom(dom, preProps, nextProps) {
.forEach(name => {
if (name.slice(0, 2) === 'on') {
// onclick => chick
dom.removeEventListener(name.slice(0, 2).toLowerCase(), preProps[name], false)
dom.addEventListener(name.slice(2).toLowerCase(), preProps[name], false)
} else {
dom[name] = nextProps[name]
}
Expand Down Expand Up @@ -748,4 +748,9 @@ function commitDeletion(fiber, domParent) {
}
}
// ...
```
```

### Hooks

实际上 hooks 是通过链表来查找具体的 state, 这里我们通过数组来简单模拟一下,把 userState 存储的 hooks, 存储在 fiber 中

4 changes: 2 additions & 2 deletions src/yolkjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function updateDom(dom, preProps, nextProps) {
.forEach(name => {
if (name.slice(0, 2) === 'on') {
// onclick => chick
dom.removeEventListener(name.slice(0, 2).toLowerCase(), preProps[name], false)
dom.removeEventListener(name.slice(2).toLowerCase(), preProps[name], false)
} else {
dom[name] = ''
}
Expand All @@ -72,7 +72,7 @@ function updateDom(dom, preProps, nextProps) {
.forEach(name => {
if (name.slice(0, 2) === 'on') {
// onclick => chick
dom.removeEventListener(name.slice(0, 2).toLowerCase(), preProps[name], false)
dom.addEventListener(name.slice(2).toLowerCase(), preProps[name], false)
} else {
dom[name] = nextProps[name]
}
Expand Down

0 comments on commit 9a45bd0

Please sign in to comment.