supports pure element
This commit is contained in:
parent
85abfeb5ca
commit
a6cce335ac
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
|
||||
<head></head>
|
||||
|
||||
<body>
|
||||
<script src="b.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
import { render, define } from "../../src/omi";
|
||||
|
||||
//Do not use pure element in browsers that do not support Reflect, such as ie11.
|
||||
define('my-ele', function (props) {
|
||||
console.log(props)
|
||||
return (
|
||||
<ul>
|
||||
{props.items.map(item => (
|
||||
<li key={item.id}>{item.text}</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
const items = [{ text: 'Omi', id: 1 }, { text: "Tencent", id: 2 }]
|
||||
render(<my-ele items={items} />, "body");
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
"mobx": "rollup -c config/rollup.example.js --watch",
|
||||
"todo-app": "rollup -c config/rollup.example.js --watch",
|
||||
"store": "rollup -c config/rollup.example.js --watch",
|
||||
"pure": "rollup -c config/rollup.example.js --watch",
|
||||
"render-array": "rollup -c config/rollup.example.js --watch",
|
||||
"css3transform": "rollup -c config/rollup.example.js --watch",
|
||||
"tap": "rollup -c config/rollup.example.js --watch",
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
import WeElement from './we-element'
|
||||
const OBJECTTYPE = "[object Object]"
|
||||
const ARRAYTYPE = "[object Array]"
|
||||
const FUNCTION = "function"
|
||||
|
||||
export function define(name, ctor) {
|
||||
customElements.define(name, ctor)
|
||||
if (ctor.data && !ctor.pure) {
|
||||
ctor.updatePath = getUpdatePath(ctor.data)
|
||||
if (typeof ctor === FUNCTION) {
|
||||
if (window.Reflect === undefined) {
|
||||
throw 'Do not use pure element in browsers that do not support Reflect.'
|
||||
}
|
||||
|
||||
function CustomElement() {
|
||||
return Reflect.construct(WeElement, [], CustomElement)
|
||||
}
|
||||
|
||||
CustomElement.pure = true
|
||||
CustomElement.prototype.render = ctor
|
||||
Object.setPrototypeOf(CustomElement.prototype, WeElement.prototype)
|
||||
Object.setPrototypeOf(CustomElement, WeElement)
|
||||
|
||||
customElements.define(name, CustomElement)
|
||||
} else {
|
||||
customElements.define(name, ctor)
|
||||
if (ctor.data && !ctor.pure) {
|
||||
ctor.updatePath = getUpdatePath(ctor.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ const omi = {
|
|||
}
|
||||
|
||||
options.root.Omi = omi
|
||||
options.root.Omi.version = "4.0.7"
|
||||
options.root.Omi.version = "4.0.8"
|
||||
|
||||
export default omi
|
||||
|
||||
|
|
Loading…
Reference in New Issue