This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

优化vm定义,增加双下划线开头的属性为非监控属性的设定; :repeat指令更名为:for, 同时修复对象遍历选项改变后视图不同步的bug

old
宇天 2018-07-31 22:16:54 +08:00
parent a33cc30995
commit 35d4b39c7a
9 changed files with 293 additions and 141 deletions

View File

@ -1554,7 +1554,7 @@ const _Anot = (function() {
}
//一些不需要被监听的属性
var $$skipArray = oneObject(
var kernelProps = oneObject(
'$id,$watch,$fire,$events,$model,$active,$pathname,$up,$ups,$track,$accessors'
)
@ -1567,6 +1567,11 @@ const _Anot = (function() {
return observeObject(source, options)
}
function isSkip(k) {
return
k.charAt(0) === '$' || k.slice(0, 2) === '__' || kernelProps[k]
}
//监听对象属性值的变化(注意,数组元素不是数组的属性),通过对劫持当前对象的访问器实现
//监听对象或数组的结构变化, 对对象的键值对进行增删重排, 或对数组的进行增删重排,都属于这范畴
// 通过比较前后代理VM顺序实现
@ -1591,7 +1596,7 @@ const _Anot = (function() {
var hasOwn = {}
var skip = []
var simple = []
var $skipArray = {}
var userSkip = {}
// 提取 source中的配置项, 并删除相应字段
var state = source.state
var computed = source.computed
@ -1607,7 +1612,7 @@ const _Anot = (function() {
delete source.watch
if (source.skip) {
$skipArray = oneObject(source.skip)
userSkip = oneObject(source.skip)
delete source.skip
}
@ -1620,14 +1625,13 @@ const _Anot = (function() {
}
for (name in state) {
var value = state[name]
if (!$$skipArray[name]) {
if (!kernelProps[name]) {
hasOwn[name] = true
}
if (
typeof value === 'function' ||
(value && value.nodeName && value.nodeType > 0) ||
(!force[name] &&
(name.charAt(0) === '$' || $$skipArray[name] || $skipArray[name]))
(!force[name] && (isSkip(name) || userSkip[name]))
) {
skip.push(name)
} else if (isComputed(value)) {
@ -1954,7 +1958,7 @@ const _Anot = (function() {
}
/*********************************************************************
* 监控数组:repeat配合使用 *
* 监控数组:for配合使用 *
**********************************************************************/
var arrayMethods = ['push', 'pop', 'shift', 'unshift', 'splice']
@ -3386,7 +3390,7 @@ const _Anot = (function() {
for (var i = 0, attr; (attr = attributes[i++]); ) {
var name = attr.name
if (uniq[name]) {
//IE8下:repeat,:with BUG
//IE8下:for BUG
continue
}
uniq[name] = 1
@ -3465,7 +3469,7 @@ const _Anot = (function() {
}
}
var rnoscanAttrBinding = /^if|widget|repeat$/
var rnoscanAttrBinding = /^if|for$/
var rnoscanNodeBinding = /^html|include$/
function scanNodeList(elem, vmodels) {
@ -3531,7 +3535,7 @@ const _Anot = (function() {
}
function scanTag(elem, vmodels) {
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90)
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :for(90)
//--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后
var skip = elem.getAttribute('skip')
var node = elem.getAttributeNode('anot')
@ -5555,7 +5559,7 @@ const _Anot = (function() {
}
})
Anot.directive('repeat', {
Anot.directive('for', {
priority: 90,
init: function(binding) {
var type = binding.type
@ -5564,9 +5568,14 @@ const _Anot = (function() {
var elem = binding.element
if (elem.nodeType === 1) {
var vars = binding.expr.split(' in ')
binding.expr = vars.pop()
if (vars.length) {
vars = vars.pop().split(/\s+/)
}
binding.vars = vars
elem.removeAttribute(binding.name)
effectBinding(elem, binding)
binding.param = binding.param || 'el'
var rendered = getBindingCallback(
elem,
'data-rendered',
@ -5600,12 +5609,28 @@ const _Anot = (function() {
var binding = this
var xtype = this.xtype
if (xtype === 'array') {
if (!this.vars.length) {
this.vars.push('$index', 'el')
} else if (this.vars.length === 1) {
this.vars.unshift('$index')
}
this.param = this.vars[1]
} else {
this.param = '__el__'
if (!this.vars.length) {
this.vars.push('$key', '$val')
} else if (this.vars.length === 1) {
this.vars.push('$val')
}
}
this.enterCount += 1
var init = !oldValue
if (init) {
binding.$outer = {}
var check0 = '$key'
var check1 = '$val'
var check0 = this.vars[0]
var check1 = this.vars[1]
if (xtype === 'array') {
check0 = '$first'
check1 = '$last'
@ -5670,9 +5695,12 @@ const _Anot = (function() {
}
} else {
action = 'append'
proxy.$key = keyOrId
proxy.$val = value[keyOrId] //key
proxy[param] = { $key: proxy.$key, $val: proxy.$val }
proxy[check0] = keyOrId
proxy[check1] = value[keyOrId] //key
var tmp = {}
tmp[check0] = proxy[check0]
tmp[check1] = proxy[check1]
proxy[param] = tmp
}
this.cache[keyOrId] = proxy
var node = proxy.$anchor || (proxy.$anchor = elem.cloneNode(false))
@ -5702,8 +5730,9 @@ const _Anot = (function() {
if (xtype === 'array') {
proxy.$first = i === 0
proxy.$last = i === length - 1
proxy[this.vars[0]] = proxy.$index
} else {
proxy.$val = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
proxy[check1] = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
}
proxies.push(proxy)
}
@ -5777,7 +5806,7 @@ const _Anot = (function() {
}
}
//repeat --> duplex
// :for --> duplex
;(function(args) {
_parent.args = args
if (_parent.msRendered) {
@ -5890,13 +5919,16 @@ const _Anot = (function() {
binding.$repeat.removeAt(proxy.$index)
}
var param = binding.param
proxy.$watch(param, function(a) {
proxy.$watch(param, function(val) {
var index = proxy.$index
binding.$repeat[index] = a
binding.$repeat[index] = val
})
} else {
proxy.$watch('$val', function fn(a) {
binding.$repeat[proxy.$key] = a
var __k__ = binding.vars[0]
var __v__ = binding.vars[1]
proxy.$up.$watch(binding.expr + '.' + proxy[__k__], function(val) {
proxy[binding.param][__v__] = val
proxy[__v__] = val
})
}
}
@ -5914,12 +5946,14 @@ const _Anot = (function() {
}
}
if (!proxy) {
proxy = eachProxyFactory(itemName)
proxy = eachProxyFactory(data)
}
return proxy
}
function eachProxyFactory(itemName) {
function eachProxyFactory(data) {
var itemName = data.param || 'el'
var __k__ = data.vars[0]
var source = {
$outer: {},
$index: 0,
@ -5930,12 +5964,14 @@ const _Anot = (function() {
$last: false,
$remove: Anot.noop
}
source[__k__] = 0
source[itemName] = NaN
var force = {
$last: 1,
$first: 1,
$index: 1
}
force[__k__] = 1
force[itemName] = 1
var proxy = modelFactory(
{ state: source },
@ -5950,26 +5986,28 @@ const _Anot = (function() {
var withProxyPool = []
function withProxyAgent(data) {
var itemName = data.param || 'el'
return withProxyPool.pop() || withProxyFactory(itemName)
return withProxyPool.pop() || withProxyFactory(data)
}
function withProxyFactory(itemName) {
function withProxyFactory(data) {
var itemName = data.param || '__el__'
var __k__ = data.vars[0]
var __v__ = data.vars[1]
var source = {
$key: '',
$val: NaN,
$index: 0,
$oldIndex: 0,
$outer: {},
$anchor: null
}
source[__k__] = ''
source[__v__] = NaN
source[itemName] = NaN
var force = {
$key: 1,
$val: 1,
__el__: 1,
$index: 1
}
force[itemName] = 1
force[__k__] = 1
force[__v__] = 1
var proxy = modelFactory(
{ state: source },
{

View File

@ -1569,7 +1569,7 @@
}
//一些不需要被监听的属性
var $$skipArray = oneObject(
var kernelProps = oneObject(
'$id,$watch,$fire,$events,$model,$active,$pathname,$up,$ups,$track,$accessors'
)
@ -1582,6 +1582,11 @@
return observeObject(source, options)
}
function isSkip(k) {
return
k.charAt(0) === '$' || k.slice(0, 2) === '__' || kernelProps[k]
}
//监听对象属性值的变化(注意,数组元素不是数组的属性),通过对劫持当前对象的访问器实现
//监听对象或数组的结构变化, 对对象的键值对进行增删重排, 或对数组的进行增删重排,都属于这范畴
// 通过比较前后代理VM顺序实现
@ -1606,7 +1611,7 @@
var hasOwn = {}
var skip = []
var simple = []
var $skipArray = {}
var userSkip = {}
// 提取 source中的配置项, 并删除相应字段
var state = source.state
var computed = source.computed
@ -1622,7 +1627,7 @@
delete source.watch
if (source.skip) {
$skipArray = oneObject(source.skip)
userSkip = oneObject(source.skip)
delete source.skip
}
@ -1635,14 +1640,13 @@
}
for (name in state) {
var value = state[name]
if (!$$skipArray[name]) {
if (!kernelProps[name]) {
hasOwn[name] = true
}
if (
typeof value === 'function' ||
(value && value.nodeName && value.nodeType > 0) ||
(!force[name] &&
(name.charAt(0) === '$' || $$skipArray[name] || $skipArray[name]))
(!force[name] && (isSkip(name) || userSkip[name]))
) {
skip.push(name)
} else if (isComputed(value)) {
@ -1969,7 +1973,7 @@
}
/*********************************************************************
* 监控数组:repeat配合使用 *
* 监控数组:for配合使用 *
**********************************************************************/
var arrayMethods = ['push', 'pop', 'shift', 'unshift', 'splice']
@ -3401,7 +3405,7 @@
for (var i = 0, attr; (attr = attributes[i++]); ) {
var name = attr.name
if (uniq[name]) {
//IE8下:repeat,:with BUG
//IE8下:for BUG
continue
}
uniq[name] = 1
@ -3480,7 +3484,7 @@
}
}
var rnoscanAttrBinding = /^if|widget|repeat$/
var rnoscanAttrBinding = /^if|for$/
var rnoscanNodeBinding = /^html|include$/
function scanNodeList(elem, vmodels) {
@ -3546,7 +3550,7 @@
}
function scanTag(elem, vmodels) {
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90)
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :for(90)
//--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后
var skip = elem.getAttribute('skip')
var node = elem.getAttributeNode('anot')
@ -5570,7 +5574,7 @@
}
})
Anot.directive('repeat', {
Anot.directive('for', {
priority: 90,
init: function(binding) {
var type = binding.type
@ -5579,9 +5583,14 @@
var elem = binding.element
if (elem.nodeType === 1) {
var vars = binding.expr.split(' in ')
binding.expr = vars.pop()
if (vars.length) {
vars = vars.pop().split(/\s+/)
}
binding.vars = vars
elem.removeAttribute(binding.name)
effectBinding(elem, binding)
binding.param = binding.param || 'el'
var rendered = getBindingCallback(
elem,
'data-rendered',
@ -5615,12 +5624,28 @@
var binding = this
var xtype = this.xtype
if (xtype === 'array') {
if (!this.vars.length) {
this.vars.push('$index', 'el')
} else if (this.vars.length === 1) {
this.vars.unshift('$index')
}
this.param = this.vars[1]
} else {
this.param = '__el__'
if (!this.vars.length) {
this.vars.push('$key', '$val')
} else if (this.vars.length === 1) {
this.vars.push('$val')
}
}
this.enterCount += 1
var init = !oldValue
if (init) {
binding.$outer = {}
var check0 = '$key'
var check1 = '$val'
var check0 = this.vars[0]
var check1 = this.vars[1]
if (xtype === 'array') {
check0 = '$first'
check1 = '$last'
@ -5685,9 +5710,12 @@
}
} else {
action = 'append'
proxy.$key = keyOrId
proxy.$val = value[keyOrId] //key
proxy[param] = { $key: proxy.$key, $val: proxy.$val }
proxy[check0] = keyOrId
proxy[check1] = value[keyOrId] //key
var tmp = {}
tmp[check0] = proxy[check0]
tmp[check1] = proxy[check1]
proxy[param] = tmp
}
this.cache[keyOrId] = proxy
var node = proxy.$anchor || (proxy.$anchor = elem.cloneNode(false))
@ -5717,8 +5745,9 @@
if (xtype === 'array') {
proxy.$first = i === 0
proxy.$last = i === length - 1
proxy[this.vars[0]] = proxy.$index
} else {
proxy.$val = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
proxy[check1] = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
}
proxies.push(proxy)
}
@ -5792,7 +5821,7 @@
}
}
//repeat --> duplex
// :for --> duplex
;(function(args) {
_parent.args = args
if (_parent.msRendered) {
@ -5905,13 +5934,16 @@
binding.$repeat.removeAt(proxy.$index)
}
var param = binding.param
proxy.$watch(param, function(a) {
proxy.$watch(param, function(val) {
var index = proxy.$index
binding.$repeat[index] = a
binding.$repeat[index] = val
})
} else {
proxy.$watch('$val', function fn(a) {
binding.$repeat[proxy.$key] = a
var __k__ = binding.vars[0]
var __v__ = binding.vars[1]
proxy.$up.$watch(binding.expr + '.' + proxy[__k__], function(val) {
proxy[binding.param][__v__] = val
proxy[__v__] = val
})
}
}
@ -5929,12 +5961,14 @@
}
}
if (!proxy) {
proxy = eachProxyFactory(itemName)
proxy = eachProxyFactory(data)
}
return proxy
}
function eachProxyFactory(itemName) {
function eachProxyFactory(data) {
var itemName = data.param || 'el'
var __k__ = data.vars[0]
var source = {
$outer: {},
$index: 0,
@ -5945,12 +5979,14 @@
$last: false,
$remove: Anot.noop
}
source[__k__] = 0
source[itemName] = NaN
var force = {
$last: 1,
$first: 1,
$index: 1
}
force[__k__] = 1
force[itemName] = 1
var proxy = modelFactory(
{ state: source },
@ -5965,26 +6001,28 @@
var withProxyPool = []
function withProxyAgent(data) {
var itemName = data.param || 'el'
return withProxyPool.pop() || withProxyFactory(itemName)
return withProxyPool.pop() || withProxyFactory(data)
}
function withProxyFactory(itemName) {
function withProxyFactory(data) {
var itemName = data.param || '__el__'
var __k__ = data.vars[0]
var __v__ = data.vars[1]
var source = {
$key: '',
$val: NaN,
$index: 0,
$oldIndex: 0,
$outer: {},
$anchor: null
}
source[__k__] = ''
source[__v__] = NaN
source[itemName] = NaN
var force = {
$key: 1,
$val: 1,
__el__: 1,
$index: 1
}
force[itemName] = 1
force[__k__] = 1
force[__v__] = 1
var proxy = modelFactory(
{ state: source },
{

View File

@ -1554,7 +1554,7 @@ const _Anot = (function() {
}
//一些不需要被监听的属性
var $$skipArray = oneObject(
var kernelProps = oneObject(
'$id,$watch,$fire,$events,$model,$active,$pathname,$up,$ups,$track,$accessors'
)
@ -1567,6 +1567,11 @@ const _Anot = (function() {
return observeObject(source, options)
}
function isSkip(k) {
return
k.charAt(0) === '$' || k.slice(0, 2) === '__' || kernelProps[k]
}
//监听对象属性值的变化(注意,数组元素不是数组的属性),通过对劫持当前对象的访问器实现
//监听对象或数组的结构变化, 对对象的键值对进行增删重排, 或对数组的进行增删重排,都属于这范畴
// 通过比较前后代理VM顺序实现
@ -1591,7 +1596,7 @@ const _Anot = (function() {
var hasOwn = {}
var skip = []
var simple = []
var $skipArray = {}
var userSkip = {}
// 提取 source中的配置项, 并删除相应字段
var state = source.state
var computed = source.computed
@ -1607,7 +1612,7 @@ const _Anot = (function() {
delete source.watch
if (source.skip) {
$skipArray = oneObject(source.skip)
userSkip = oneObject(source.skip)
delete source.skip
}
@ -1620,14 +1625,13 @@ const _Anot = (function() {
}
for (name in state) {
var value = state[name]
if (!$$skipArray[name]) {
if (!kernelProps[name]) {
hasOwn[name] = true
}
if (
typeof value === 'function' ||
(value && value.nodeName && value.nodeType > 0) ||
(!force[name] &&
(name.charAt(0) === '$' || $$skipArray[name] || $skipArray[name]))
(!force[name] && (isSkip(name) || userSkip[name]))
) {
skip.push(name)
} else if (isComputed(value)) {
@ -1954,7 +1958,7 @@ const _Anot = (function() {
}
/*********************************************************************
* 监控数组:repeat配合使用 *
* 监控数组:for配合使用 *
**********************************************************************/
var arrayMethods = ['push', 'pop', 'shift', 'unshift', 'splice']
@ -3386,7 +3390,7 @@ const _Anot = (function() {
for (var i = 0, attr; (attr = attributes[i++]); ) {
var name = attr.name
if (uniq[name]) {
//IE8下:repeat,:with BUG
//IE8下:for BUG
continue
}
uniq[name] = 1
@ -3465,7 +3469,7 @@ const _Anot = (function() {
}
}
var rnoscanAttrBinding = /^if|widget|repeat$/
var rnoscanAttrBinding = /^if|for$/
var rnoscanNodeBinding = /^html|include$/
function scanNodeList(elem, vmodels) {
@ -3531,7 +3535,7 @@ const _Anot = (function() {
}
function scanTag(elem, vmodels) {
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90)
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :for(90)
//--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后
var skip = elem.getAttribute('skip')
var node = elem.getAttributeNode('anot')
@ -5555,7 +5559,7 @@ const _Anot = (function() {
}
})
Anot.directive('repeat', {
Anot.directive('for', {
priority: 90,
init: function(binding) {
var type = binding.type
@ -5564,9 +5568,14 @@ const _Anot = (function() {
var elem = binding.element
if (elem.nodeType === 1) {
var vars = binding.expr.split(' in ')
binding.expr = vars.pop()
if (vars.length) {
vars = vars.pop().split(/\s+/)
}
binding.vars = vars
elem.removeAttribute(binding.name)
effectBinding(elem, binding)
binding.param = binding.param || 'el'
var rendered = getBindingCallback(
elem,
'data-rendered',
@ -5600,12 +5609,28 @@ const _Anot = (function() {
var binding = this
var xtype = this.xtype
if (xtype === 'array') {
if (!this.vars.length) {
this.vars.push('$index', 'el')
} else if (this.vars.length === 1) {
this.vars.unshift('$index')
}
this.param = this.vars[1]
} else {
this.param = '__el__'
if (!this.vars.length) {
this.vars.push('$key', '$val')
} else if (this.vars.length === 1) {
this.vars.push('$val')
}
}
this.enterCount += 1
var init = !oldValue
if (init) {
binding.$outer = {}
var check0 = '$key'
var check1 = '$val'
var check0 = this.vars[0]
var check1 = this.vars[1]
if (xtype === 'array') {
check0 = '$first'
check1 = '$last'
@ -5670,9 +5695,12 @@ const _Anot = (function() {
}
} else {
action = 'append'
proxy.$key = keyOrId
proxy.$val = value[keyOrId] //key
proxy[param] = { $key: proxy.$key, $val: proxy.$val }
proxy[check0] = keyOrId
proxy[check1] = value[keyOrId] //key
var tmp = {}
tmp[check0] = proxy[check0]
tmp[check1] = proxy[check1]
proxy[param] = tmp
}
this.cache[keyOrId] = proxy
var node = proxy.$anchor || (proxy.$anchor = elem.cloneNode(false))
@ -5702,8 +5730,9 @@ const _Anot = (function() {
if (xtype === 'array') {
proxy.$first = i === 0
proxy.$last = i === length - 1
proxy[this.vars[0]] = proxy.$index
} else {
proxy.$val = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
proxy[check1] = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
}
proxies.push(proxy)
}
@ -5777,7 +5806,7 @@ const _Anot = (function() {
}
}
//repeat --> duplex
// :for --> duplex
;(function(args) {
_parent.args = args
if (_parent.msRendered) {
@ -5890,13 +5919,16 @@ const _Anot = (function() {
binding.$repeat.removeAt(proxy.$index)
}
var param = binding.param
proxy.$watch(param, function(a) {
proxy.$watch(param, function(val) {
var index = proxy.$index
binding.$repeat[index] = a
binding.$repeat[index] = val
})
} else {
proxy.$watch('$val', function fn(a) {
binding.$repeat[proxy.$key] = a
var __k__ = binding.vars[0]
var __v__ = binding.vars[1]
proxy.$up.$watch(binding.expr + '.' + proxy[__k__], function(val) {
proxy[binding.param][__v__] = val
proxy[__v__] = val
})
}
}
@ -5914,12 +5946,14 @@ const _Anot = (function() {
}
}
if (!proxy) {
proxy = eachProxyFactory(itemName)
proxy = eachProxyFactory(data)
}
return proxy
}
function eachProxyFactory(itemName) {
function eachProxyFactory(data) {
var itemName = data.param || 'el'
var __k__ = data.vars[0]
var source = {
$outer: {},
$index: 0,
@ -5930,12 +5964,14 @@ const _Anot = (function() {
$last: false,
$remove: Anot.noop
}
source[__k__] = 0
source[itemName] = NaN
var force = {
$last: 1,
$first: 1,
$index: 1
}
force[__k__] = 1
force[itemName] = 1
var proxy = modelFactory(
{ state: source },
@ -5950,26 +5986,28 @@ const _Anot = (function() {
var withProxyPool = []
function withProxyAgent(data) {
var itemName = data.param || 'el'
return withProxyPool.pop() || withProxyFactory(itemName)
return withProxyPool.pop() || withProxyFactory(data)
}
function withProxyFactory(itemName) {
function withProxyFactory(data) {
var itemName = data.param || '__el__'
var __k__ = data.vars[0]
var __v__ = data.vars[1]
var source = {
$key: '',
$val: NaN,
$index: 0,
$oldIndex: 0,
$outer: {},
$anchor: null
}
source[__k__] = ''
source[__v__] = NaN
source[itemName] = NaN
var force = {
$key: 1,
$val: 1,
__el__: 1,
$index: 1
}
force[itemName] = 1
force[__k__] = 1
force[__v__] = 1
var proxy = modelFactory(
{ state: source },
{

View File

@ -1569,7 +1569,7 @@
}
//一些不需要被监听的属性
var $$skipArray = oneObject(
var kernelProps = oneObject(
'$id,$watch,$fire,$events,$model,$active,$pathname,$up,$ups,$track,$accessors'
)
@ -1582,6 +1582,11 @@
return observeObject(source, options)
}
function isSkip(k) {
return
k.charAt(0) === '$' || k.slice(0, 2) === '__' || kernelProps[k]
}
//监听对象属性值的变化(注意,数组元素不是数组的属性),通过对劫持当前对象的访问器实现
//监听对象或数组的结构变化, 对对象的键值对进行增删重排, 或对数组的进行增删重排,都属于这范畴
// 通过比较前后代理VM顺序实现
@ -1606,7 +1611,7 @@
var hasOwn = {}
var skip = []
var simple = []
var $skipArray = {}
var userSkip = {}
// 提取 source中的配置项, 并删除相应字段
var state = source.state
var computed = source.computed
@ -1622,7 +1627,7 @@
delete source.watch
if (source.skip) {
$skipArray = oneObject(source.skip)
userSkip = oneObject(source.skip)
delete source.skip
}
@ -1635,14 +1640,13 @@
}
for (name in state) {
var value = state[name]
if (!$$skipArray[name]) {
if (!kernelProps[name]) {
hasOwn[name] = true
}
if (
typeof value === 'function' ||
(value && value.nodeName && value.nodeType > 0) ||
(!force[name] &&
(name.charAt(0) === '$' || $$skipArray[name] || $skipArray[name]))
(!force[name] && (isSkip(name) || userSkip[name]))
) {
skip.push(name)
} else if (isComputed(value)) {
@ -1969,7 +1973,7 @@
}
/*********************************************************************
* 监控数组:repeat配合使用 *
* 监控数组:for配合使用 *
**********************************************************************/
var arrayMethods = ['push', 'pop', 'shift', 'unshift', 'splice']
@ -3401,7 +3405,7 @@
for (var i = 0, attr; (attr = attributes[i++]); ) {
var name = attr.name
if (uniq[name]) {
//IE8下:repeat,:with BUG
//IE8下:for BUG
continue
}
uniq[name] = 1
@ -3480,7 +3484,7 @@
}
}
var rnoscanAttrBinding = /^if|widget|repeat$/
var rnoscanAttrBinding = /^if|for$/
var rnoscanNodeBinding = /^html|include$/
function scanNodeList(elem, vmodels) {
@ -3546,7 +3550,7 @@
}
function scanTag(elem, vmodels) {
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90)
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :for(90)
//--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后
var skip = elem.getAttribute('skip')
var node = elem.getAttributeNode('anot')
@ -5570,7 +5574,7 @@
}
})
Anot.directive('repeat', {
Anot.directive('for', {
priority: 90,
init: function(binding) {
var type = binding.type
@ -5579,9 +5583,14 @@
var elem = binding.element
if (elem.nodeType === 1) {
var vars = binding.expr.split(' in ')
binding.expr = vars.pop()
if (vars.length) {
vars = vars.pop().split(/\s+/)
}
binding.vars = vars
elem.removeAttribute(binding.name)
effectBinding(elem, binding)
binding.param = binding.param || 'el'
var rendered = getBindingCallback(
elem,
'data-rendered',
@ -5615,12 +5624,28 @@
var binding = this
var xtype = this.xtype
if (xtype === 'array') {
if (!this.vars.length) {
this.vars.push('$index', 'el')
} else if (this.vars.length === 1) {
this.vars.unshift('$index')
}
this.param = this.vars[1]
} else {
this.param = '__el__'
if (!this.vars.length) {
this.vars.push('$key', '$val')
} else if (this.vars.length === 1) {
this.vars.push('$val')
}
}
this.enterCount += 1
var init = !oldValue
if (init) {
binding.$outer = {}
var check0 = '$key'
var check1 = '$val'
var check0 = this.vars[0]
var check1 = this.vars[1]
if (xtype === 'array') {
check0 = '$first'
check1 = '$last'
@ -5685,9 +5710,12 @@
}
} else {
action = 'append'
proxy.$key = keyOrId
proxy.$val = value[keyOrId] //key
proxy[param] = { $key: proxy.$key, $val: proxy.$val }
proxy[check0] = keyOrId
proxy[check1] = value[keyOrId] //key
var tmp = {}
tmp[check0] = proxy[check0]
tmp[check1] = proxy[check1]
proxy[param] = tmp
}
this.cache[keyOrId] = proxy
var node = proxy.$anchor || (proxy.$anchor = elem.cloneNode(false))
@ -5717,8 +5745,9 @@
if (xtype === 'array') {
proxy.$first = i === 0
proxy.$last = i === length - 1
proxy[this.vars[0]] = proxy.$index
} else {
proxy.$val = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
proxy[check1] = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
}
proxies.push(proxy)
}
@ -5792,7 +5821,7 @@
}
}
//repeat --> duplex
// :for --> duplex
;(function(args) {
_parent.args = args
if (_parent.msRendered) {
@ -5905,13 +5934,16 @@
binding.$repeat.removeAt(proxy.$index)
}
var param = binding.param
proxy.$watch(param, function(a) {
proxy.$watch(param, function(val) {
var index = proxy.$index
binding.$repeat[index] = a
binding.$repeat[index] = val
})
} else {
proxy.$watch('$val', function fn(a) {
binding.$repeat[proxy.$key] = a
var __k__ = binding.vars[0]
var __v__ = binding.vars[1]
proxy.$up.$watch(binding.expr + '.' + proxy[__k__], function(val) {
proxy[binding.param][__v__] = val
proxy[__v__] = val
})
}
}
@ -5929,12 +5961,14 @@
}
}
if (!proxy) {
proxy = eachProxyFactory(itemName)
proxy = eachProxyFactory(data)
}
return proxy
}
function eachProxyFactory(itemName) {
function eachProxyFactory(data) {
var itemName = data.param || 'el'
var __k__ = data.vars[0]
var source = {
$outer: {},
$index: 0,
@ -5945,12 +5979,14 @@
$last: false,
$remove: Anot.noop
}
source[__k__] = 0
source[itemName] = NaN
var force = {
$last: 1,
$first: 1,
$index: 1
}
force[__k__] = 1
force[itemName] = 1
var proxy = modelFactory(
{ state: source },
@ -5965,26 +6001,28 @@
var withProxyPool = []
function withProxyAgent(data) {
var itemName = data.param || 'el'
return withProxyPool.pop() || withProxyFactory(itemName)
return withProxyPool.pop() || withProxyFactory(data)
}
function withProxyFactory(itemName) {
function withProxyFactory(data) {
var itemName = data.param || '__el__'
var __k__ = data.vars[0]
var __v__ = data.vars[1]
var source = {
$key: '',
$val: NaN,
$index: 0,
$oldIndex: 0,
$outer: {},
$anchor: null
}
source[__k__] = ''
source[__v__] = NaN
source[itemName] = NaN
var force = {
$key: 1,
$val: 1,
__el__: 1,
$index: 1
}
force[itemName] = 1
force[__k__] = 1
force[__v__] = 1
var proxy = modelFactory(
{ state: source },
{

View File

@ -164,7 +164,7 @@ export default Anot.component('datepicker', {
<section class="tr do-fn-cl">
<span class="td"
:class="{weeken:el.weeken, disabled: el.disabled, selected: el.selected}"
:repeat="calendar.list"
:for="calendar.list"
:click="pick(el)"
:text="el.day"></span>
</section>

View File

@ -122,7 +122,7 @@ const fixCont = function(vm, tool) {
<span class="col">操作</span>
</li>
<li class="tbody">
<p :repeat="uploadQueue">
<p :for="uploadQueue">
<span
class="col do-fn-ell"
:text="el.name"
@ -137,7 +137,7 @@ const fixCont = function(vm, tool) {
<ul class="list-box">
<li
class="item"
:repeat="attachList"
:for="attachList"
:layer-tips="el.name"
:click="insert(el)">

View File

@ -239,7 +239,7 @@ const addon = {
},
content: `
<ul class="do-meditor-face">
<li class="item" :repeat="arr">
<li class="item" :for="arr">
<span :html="el" :click="insert(el)"></span>
</li>
</ul>`,
@ -273,9 +273,9 @@ const addon = {
}),
content: `
<ul class="do-meditor-table" ref="table">
<li :repeat="matrix">
<li :for="matrix">
<span
:repeat-o="el"
:for="o in el"
:class="{active: o.v}"
:data="{x: $index, y: $outer.$index}"></span>
</li>
@ -442,7 +442,7 @@ const addon = {
<section class="do-fn-cl">
<span class="label">语言类型</span>
<select :duplex="lang">
<option :repeat="$lang" :attr-value="el.id">{{el.name || el.id}}</option>
<option :for="$lang" :attr-value="el.id">{{el.name || el.id}}</option>
</select>
</section>
<section>

View File

@ -79,7 +79,7 @@ const tmpls = {
:data="{to: parseUrl(currPage + 1)}"
:click="go(currPage + 1, $event)"></button>`,
pager: `<button class="page"
:repeat="pageList"
:for="pageList"
:css="{'border-radius': props.radius}"
:attr="{disabled: '...' === el || currPage === el}"
:data="{to: parseUrl(el)}"

View File

@ -67,7 +67,7 @@ export default Anot.component('tree', {
let { multiCheck } = this
return `
<section class="do-tree__item" :repeat="list" :class="{open: el.__open__, dir: el.children}">
<section class="do-tree__item" :for="list" :class="{open: el.__open__, dir: el.children}">
<em
:class="{
'do-icon-txt': !el.children,