omio - fix path updating
This commit is contained in:
parent
f13e2a600d
commit
37595f2b6b
|
@ -1698,9 +1698,9 @@
|
|||
extendStoreUpate(store);
|
||||
var timeout = null;
|
||||
var patchs = {};
|
||||
obaa(store.data, function (path, a, b) {
|
||||
obaa(store.data, function (prop, val, old, path) {
|
||||
clearTimeout(timeout);
|
||||
var key = fixPath(path);
|
||||
var key = fixPath(path + '-' + prop);
|
||||
patchs[key] = true;
|
||||
timeout = setTimeout(function () {
|
||||
store.update(patchs);
|
||||
|
@ -1781,7 +1781,7 @@
|
|||
|
||||
function fixPath(path) {
|
||||
var mpPath = '';
|
||||
var arr = path.replace('/', '').split('/');
|
||||
var arr = path.replace('#-', '').split('-');
|
||||
arr.forEach(function (item, index) {
|
||||
if (index) {
|
||||
if (isNaN(Number(item))) {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -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>
|
|
@ -0,0 +1,77 @@
|
|||
import { render, WeElement, define } from '../../src/omi'
|
||||
|
||||
define('my-counter', class extends WeElement {
|
||||
static use = [
|
||||
'count',
|
||||
'arr[0]',
|
||||
{
|
||||
reverseMotto: [
|
||||
'motto',
|
||||
target => target.split('').reverse().join('')
|
||||
]
|
||||
},
|
||||
{ name: 'arr[1]' },
|
||||
{
|
||||
fullName: [
|
||||
['userInfo.firstName', 'userInfo.lastName'],
|
||||
(firstName, lastName) => firstName + lastName
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
sub = () => this.store.sub()
|
||||
add = () => this.store.add()
|
||||
rename = () => this.store.rename('dnt')
|
||||
changeMotto = () => this.store.changeMotto('Hello omi!')
|
||||
changeFirstName = () => this.store.changeFirstName('Dnt')
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<button onClick={this.sub}>-</button>
|
||||
<span>{this.use[0]}</span>
|
||||
<button onClick={this.add}>+</button>
|
||||
<div>
|
||||
<span>{this.use[1]}</span>
|
||||
<button onClick={this.rename}>rename</button>
|
||||
</div>
|
||||
<div>{this.use.reverseMotto}</div><button onClick={this.changeMotto}>change motto</button>
|
||||
<div>{this.use.name}</div>
|
||||
<div>{this.use[3]}</div>
|
||||
<div>
|
||||
{this.use.fullName}
|
||||
<button onClick={this.changeFirstName}>change first name</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
render(<my-counter />, 'body', {
|
||||
data: {
|
||||
count: 0,
|
||||
arr: ['china', 'tencent'],
|
||||
motto: 'I love omi.',
|
||||
userInfo: {
|
||||
firstName: 'dnt',
|
||||
lastName: 'zhang',
|
||||
age: 18
|
||||
}
|
||||
},
|
||||
sub() {
|
||||
this.data.count--
|
||||
},
|
||||
add() {
|
||||
this.data.count++
|
||||
},
|
||||
rename(newName) {
|
||||
console.log(1)
|
||||
this.data.arr[0] = newName
|
||||
},
|
||||
changeMotto(motto) {
|
||||
this.data.motto = motto
|
||||
},
|
||||
changeFirstName(firstName) {
|
||||
this.data.userInfo.firstName = firstName
|
||||
}
|
||||
})
|
|
@ -21,6 +21,7 @@
|
|||
"children": "rollup -c config/rollup.example.js --watch",
|
||||
"counter": "rollup -c config/rollup.example.js --watch",
|
||||
"store-counter": "rollup -c config/rollup.example.js --watch",
|
||||
"store-demo": "rollup -c config/rollup.example.js --watch",
|
||||
"fire": "rollup -c config/rollup.example.js --watch",
|
||||
"receive-props": "rollup -c config/rollup.example.js --watch",
|
||||
"rpx": "rollup -c config/rollup.example.js --watch",
|
||||
|
|
|
@ -15,9 +15,9 @@ export function render(vnode, parent, store, empty, merge) {
|
|||
extendStoreUpate(store)
|
||||
let timeout = null
|
||||
let patchs = {}
|
||||
obaa(store.data, (path,a,b)=> {
|
||||
obaa(store.data, (prop, val, old, path) => {
|
||||
clearTimeout(timeout)
|
||||
const key = fixPath(path)
|
||||
const key = fixPath(path + '-' + prop)
|
||||
patchs[key] = true
|
||||
timeout = setTimeout(() => {
|
||||
store.update(patchs)
|
||||
|
@ -105,7 +105,7 @@ function includePath(pathA, pathB) {
|
|||
|
||||
export function fixPath(path) {
|
||||
let mpPath = ''
|
||||
const arr = path.replace('/', '').split('/')
|
||||
const arr = path.replace('#-', '').split('-')
|
||||
arr.forEach((item, index) => {
|
||||
if (index) {
|
||||
if (isNaN(Number(item))) {
|
||||
|
|
Loading…
Reference in New Issue