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

更新无加载器版anot

old
宇天 2018-05-23 19:07:18 +08:00
parent c1b678569d
commit aae31d946d
1 changed files with 66 additions and 46 deletions

View File

@ -219,6 +219,7 @@ const _Anot = (function() {
vm.$id = $id vm.$id = $id
VMODELS[$id] = vm VMODELS[$id] = vm
Anot.nextTick(function() {
var $elem = document.querySelector('[anot=' + vm.$id + ']') var $elem = document.querySelector('[anot=' + vm.$id + ']')
if ($elem) { if ($elem) {
if ($elem === DOC.body) { if ($elem === DOC.body) {
@ -230,9 +231,14 @@ const _Anot = (function() {
break break
} }
} }
scanTag($elem.parentNode, $parent ? [VMODELS[$parent.anotctrl]] : []) scanTag(
$elem.parentNode,
$parent ? [VMODELS[$parent.anotctrl]] : []
)
} }
} }
})
return vm return vm
} else { } else {
this[0] = this.element = source this[0] = this.element = source
@ -1714,6 +1720,7 @@ const _Anot = (function() {
hideProperty($vmodel, '$refs', {}) hideProperty($vmodel, '$refs', {})
hideProperty($vmodel, '$children', []) hideProperty($vmodel, '$children', [])
hideProperty($vmodel, 'hasOwnProperty', trackBy) hideProperty($vmodel, 'hasOwnProperty', trackBy)
hideProperty($vmodel, '$mounted', mounted)
if (options.watch) { if (options.watch) {
hideProperty($vmodel, '$watch', function() { hideProperty($vmodel, '$watch', function() {
return $watch.apply($vmodel, arguments) return $watch.apply($vmodel, arguments)
@ -1758,7 +1765,6 @@ const _Anot = (function() {
} }
$vmodel.$active = true $vmodel.$active = true
$vmodel.mounted = mounted
if (old && old.$up && old.$up.$children) { if (old && old.$up && old.$up.$children) {
old.$up.$children.push($vmodel) old.$up.$children.push($vmodel)
@ -1909,6 +1915,7 @@ const _Anot = (function() {
configurable: true configurable: true
}) })
} }
Anot.hideProperty = hideProperty
function toJson(val) { function toJson(val) {
var xtype = Anot.type(val) var xtype = Anot.type(val)
@ -2157,6 +2164,7 @@ const _Anot = (function() {
injectDependency(array, binding) injectDependency(array, binding)
} }
}) })
binding.getter = parseExpr(binding.expr, binding.vmodels, binding) binding.getter = parseExpr(binding.expr, binding.vmodels, binding)
binding.observers.forEach(function(a) { binding.observers.forEach(function(a) {
a.v.$watch(a.p, binding) a.v.$watch(a.p, binding)
@ -3023,8 +3031,8 @@ const _Anot = (function() {
} }
function addAssign(vars, vmodel, name, binding) { function addAssign(vars, vmodel, name, binding) {
var ret = [], var ret = []
prefix = ' = ' + name + '.' var prefix = ' = ' + name + '.'
for (var i = vars.length, prop; (prop = vars[--i]); ) { for (var i = vars.length, prop; (prop = vars[--i]); ) {
var arr = prop.split('.') var arr = prop.split('.')
var first = arr[0] var first = arr[0]
@ -3122,7 +3130,7 @@ const _Anot = (function() {
/* jshint ignore:start */ /* jshint ignore:start */
var fn2 = scpCompile( var fn2 = scpCompile(
names.concat( names.concat(
"'use strict';" + 'return function(vvv){' + expr + ' = vvv\n}\n' '"use strict";\n return function(vvv){' + expr + ' = vvv\n}\n'
) )
) )
/* jshint ignore:end */ /* jshint ignore:end */
@ -3163,6 +3171,7 @@ const _Anot = (function() {
}) })
expr = '\nreturn ' + expr + ';' //IE全家 Function("return ")出错需要Function("return ;") expr = '\nreturn ' + expr + ';' //IE全家 Function("return ")出错需要Function("return ;")
} }
/* jshint ignore:start */ /* jshint ignore:start */
getter = scpCompile( getter = scpCompile(
names.concat( names.concat(
@ -3275,7 +3284,7 @@ const _Anot = (function() {
Anot.injectBinding(binding) Anot.injectBinding(binding)
if (binding.getter && binding.element.nodeType === 1) { if (binding.getter && binding.element.nodeType === 1) {
//移除数据绑定,防止被二次解析 //移除数据绑定,防止被二次解析
//chrome使用removeAttributeNode移除不存在的特性节点时会报错 https://github.com/RubyLouvre/Anot/issues/99 //chrome使用removeAttributeNode移除不存在的特性节点时会报错
binding.element.removeAttribute(binding.name) binding.element.removeAttribute(binding.name)
} }
} }
@ -3331,10 +3340,22 @@ const _Anot = (function() {
delete elem[attr.value] delete elem[attr.value]
} else { } else {
var camelizeName = camelize(name) var camelizeName = camelize(name)
if (camelizeName.indexOf('@') === 0) {
camelizeName = camelizeName.slice(1)
var vm = vmodels[0]
if (
vm &&
vm.hasOwnProperty(attr.value) &&
typeof vm[attr.value] === 'function'
) {
ret[camelizeName] = vm[attr.value].bind(vm)
}
} else {
ret[camelizeName] = parseData(attr.value) ret[camelizeName] = parseData(attr.value)
} }
} }
} }
}
return ret return ret
} }
@ -3490,8 +3511,8 @@ const _Anot = (function() {
} }
function scanTag(elem, vmodels, node) { function scanTag(elem, vmodels, node) {
//扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(100) //扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90)
//--> :if-loop(110) --> :attr(970) ...--> :each(1400)-->:with(1500)--〉:duplex(2000)垫后 //--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后
var skip = elem.getAttribute('skip') var skip = elem.getAttribute('skip')
node = elem.getAttributeNode('anot') node = elem.getAttributeNode('anot')
var vm = vmodels.concat() var vm = vmodels.concat()
@ -3542,15 +3563,16 @@ const _Anot = (function() {
newVmodel.props[k] = props[k] newVmodel.props[k] = props[k]
delete props[k] delete props[k]
} else { } else {
Anot.error( console.error(
new TypeError(
'props.' + 'props.' +
k + k +
' needs [' + ' needs [' +
newVmodel.props[k].checkType + newVmodel.props[k].checkType +
'], but [' + '], but [' +
newVmodel.props[k].result + newVmodel.props[k].result +
'] given.', '] given.'
TypeError )
) )
} }
} }
@ -3563,10 +3585,10 @@ const _Anot = (function() {
if (newVmodel) { if (newVmodel) {
setTimeout(function() { setTimeout(function() {
if (typeof newVmodel.mounted === 'function') { if (typeof newVmodel.$mounted === 'function') {
newVmodel.mounted() newVmodel.$mounted()
} }
delete newVmodel.mounted delete newVmodel.$mounted
}) })
} }
} }
@ -3769,7 +3791,7 @@ const _Anot = (function() {
delete hooks.componentWillUnmount delete hooks.componentWillUnmount
var vmodel = Anot(hooks) var vmodel = Anot(hooks)
delete vmodel.mounted delete vmodel.$mounted
host.vmodels[0].$children.push(vmodel) host.vmodels[0].$children.push(vmodel)
elem.msResolved = 1 //防止二进扫描此元素 elem.msResolved = 1 //防止二进扫描此元素
@ -3980,6 +4002,12 @@ const _Anot = (function() {
console.error('设置style样式, 请改用 :css指令') console.error('设置style样式, 请改用 :css指令')
continue continue
} }
// 通过属性设置回调,必须以@符号开头
if (i.indexOf('@') === 0) {
if (typeof obj[i] !== 'function') {
continue
}
}
if (i === 'href' || i === 'src') { if (i === 'href' || i === 'src') {
//处理IE67自动转义的问题 //处理IE67自动转义的问题
if (!root.hasAttribute) obj[i] = obj[i].replace(/&/g, '&') if (!root.hasAttribute) obj[i] = obj[i].replace(/&/g, '&')
@ -4026,7 +4054,7 @@ const _Anot = (function() {
if (typeof obj[i] === 'object') { if (typeof obj[i] === 'object') {
obj[i] = JSON.stringify(obj[i]) obj[i] = JSON.stringify(obj[i])
} else if (typeof obj[i] === 'function') { } else if (typeof obj[i] === 'function') {
k = '__fn__' + camelize(k) k = ronattr + camelize(k.slice(1))
elem[k] = obj[i].bind(vm) elem[k] = obj[i].bind(vm)
obj[i] = k obj[i] = k
} }
@ -4189,7 +4217,6 @@ const _Anot = (function() {
} }
return true return true
} }
Anot.directive('rule', { Anot.directive('rule', {
priority: 2010, priority: 2010,
init: function(binding) { init: function(binding) {
@ -5449,11 +5476,6 @@ const _Anot = (function() {
var kill = elem.previousSibling var kill = elem.previousSibling
var start = binding.start var start = binding.start
/*log(kill === start, kill)
while(kill !== start && kill.nodeName !== '#comment'){
parent.removeChild(kill)
kill = elem.previousSibling
}*/
if (clear) { if (clear) {
while (kill !== start) { while (kill !== start) {
parent.removeChild(kill) parent.removeChild(kill)
@ -5495,9 +5517,6 @@ const _Anot = (function() {
) )
decorateProxy(proxy, binding, xtype) decorateProxy(proxy, binding, xtype)
} else { } else {
// if (xtype === "array") {
// proxy[param] = value[i]
// }
fragments.push({}) fragments.push({})
retain[keyOrId] = true retain[keyOrId] = true
} }
@ -5514,7 +5533,6 @@ const _Anot = (function() {
if (xtype === 'array') { if (xtype === 'array') {
proxy.$first = i === 0 proxy.$first = i === 0
proxy.$last = i === length - 1 proxy.$last = i === length - 1
// proxy[param] = value[i]
} else { } else {
proxy.$val = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况 proxy.$val = toJson(value[keyOrId]) //这里是处理vm.object = newObject的情况
} }
@ -6047,7 +6065,9 @@ const _Anot = (function() {
} }
oDate = new Date(stamp) oDate = new Date(stamp)
if (oDate + '' === 'Invalid Date') return 'Invalid Date' if (oDate + '' === 'Invalid Date') {
return 'Invalid Date'
}
} else { } else {
oDate = stamp oDate = stamp
} }