omio - fix isSameNodeType method

This commit is contained in:
dntzhang 2018-12-14 09:02:39 +08:00
parent 39f201c6f5
commit 8e5e9853c2
6 changed files with 1860 additions and 6 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,16 @@
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<meta charset="UTF-8" />
<title>Add Omi in 30 Seconds</title>
</head>
<body>
<script src="b.js"></script>
<a href="https://github.com/Tencent/omi" target="_blank" style="position: fixed; right: 0; top: 0; z-index: 3;">
<img src="//alloyteam.github.io/github.png" alt="">
</a>
</body>
</html>

View File

@ -0,0 +1,51 @@
import { render, WeElement, define } from '../../src/omi'
define('my-counter', class extends WeElement {
static observe = true
data = {
count: 1
}
sub = () => {
this.data.count--
}
add = () => {
this.data.count++
}
receiveProps(props, data, old) {
console.log(old)
data.count = props.value
}
render() {
console.log(111)
return (
<div>
<button onClick={this.sub}>-</button>
<span>{this.data.count}</span>
<button onClick={this.add}>+</button>
</div>
)
}
})
define('my-app', class extends WeElement {
reset = () => {
this.value = Math.floor(Math.random() * 100)
this.update()
}
render() {
return (
<div>
<my-counter value={this.value} />
<button onClick={this.reset}>reset value</button>
</div>
)
}
})
render(<my-app />, 'body')

View File

@ -1,6 +1,6 @@
{
"name": "omio",
"version": "0.0.1",
"version": "0.0.2",
"description": "Omi for old browsers(IE9+ and mobile browsers).",
"main": "dist/omi.js",
"jsnext:main": "dist/omi.esm.js",
@ -18,6 +18,7 @@
"store": "rollup -c config/rollup.example.js --watch",
"children": "rollup -c config/rollup.example.js --watch",
"counter": "rollup -c config/rollup.example.js --watch",
"receive-props": "rollup -c config/rollup.example.js --watch",
"omi-tap": "rollup -c config/rollup.example.js --watch",
"simple": "rollup -c config/rollup.example.js --watch",
"transpile:main": "rollup -c config/rollup.config.js",

View File

@ -1,5 +1,5 @@
import { extend } from '../util'
import options from '../options'
/**
* Check if two nodes are equivalent.
*
@ -12,10 +12,11 @@ export function isSameNodeType(node, vnode, hydrating) {
if (typeof vnode === 'string' || typeof vnode === 'number') {
return node.splitText !== undefined
}
if (typeof vnode.nodeName === 'string') {
return !node._componentConstructor && isNamedNode(node, vnode.nodeName)
}
return hydrating || node._componentConstructor === vnode.nodeName
const ctor = options.mapping[vnode.nodeName]
if(ctor){
return hydrating || node._componentConstructor === ctor
}
return !node._componentConstructor && isNamedNode(node, vnode.nodeName)
}
/**