Skip to content

Commit

Permalink
update 心跳检测
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Aug 21, 2014
1 parent 0034f0c commit a54ab14
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 49 deletions.
47 changes: 22 additions & 25 deletions avalon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3067,31 +3067,26 @@
}
if (vmodel.hasOwnProperty("$remove")) {
var offTree = function() {
vmodel.$remove()
elem.msData = {}
delete VMODELS[vmodel.$id]
if (VMODELS[vmodel.$id]) {
vmodel.$remove()
elem.msData = {}
delete VMODELS[vmodel.$id]
}
}
if (supportMutationEvents) {
elem.addEventListener("DOMNodeRemoved", function(e) {
if (e.target === this && !this.msRetain &&
//#441 chrome浏览器对文本域进行Ctrl+V操作,会触发DOMNodeRemoved事件
(window.chrome ? this.tagName === "INPUT" && e.relatedNode.nodeType === 1 : 1)) {
if (window.chrome) {
elem.addEventListener("DOMNodeRemovedFromDocument", function(e) {
if (!this.msRetain) {
offTree()
}
})
} else {
elem.offTree = offTree
launchImpl(elem)
}
avalon.tick(offTree)
}
} else if (vmodels.length) { //如果该组件还没有加载,那么保存当前的vmodels
elem.vmodels = vmodels
}
}
}

var supportMutationEvents = W3C && DOC.implementation.hasFeature("MutationEvents", "2.0")

//============================ class preperty binding =======================
"hover,active".replace(rword, function(method) {
bindingHandlers[method] = bindingHandlers["class"]
Expand Down Expand Up @@ -3228,11 +3223,15 @@
})
}
}

}
}
element.onTree = onTree
launch(element)
launch(function() {
if (avalon.contains(root, element)) {
onTree.call(element)
} else if (!element.msRetain) {
return false
}
})
element.oldValue = element.value
registerSubscriber(data)
var timer = setTimeout(function() {
Expand All @@ -3252,6 +3251,7 @@
}
el.dispatchEvent(event)
}

function onTree() { //disabled状态下改动不触发input事件
if (!this.disabled && this.oldValue !== this.value) {
if (W3C) {
Expand All @@ -3261,23 +3261,20 @@
}
}
}

function ticker() {
for (var n = ribbon.length - 1; n >= 0; n--) {
var el = ribbon[n]
if (avalon.contains(root, el)) {
el.onTree && el.onTree()
} else if (!el.msRetain) {
el.offTree && el.offTree()
if (el() === false) {
ribbon.splice(n, 1)
}
}
if (!ribbon.length) {
clearInterval(TimerID)
}
}
function launchImpl(el) {
if (ribbon.push(el) === 1) {

avalon.tick = function(fn) {
if (ribbon.push(fn) === 1) {
TimerID = setInterval(ticker, 30)
}
}
Expand All @@ -3296,7 +3293,7 @@
set: newSetter
})
} catch (e) {
launch = launchImpl
launch = avalon.tick
}

duplexBinding.SELECT = function(element, evaluator, data) {
Expand Down
36 changes: 12 additions & 24 deletions test1.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
<head>
<title>avalon入门</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="avalon.mobile.js" ></script>
<script src="avalon.js" ></script>
<!-- <script src="mobile.js" ></script>-->
<script>

var model = avalon.define({
$id: "test",
images: [{src: "https://www.google.com/images/srpr/logo11w.png"}],
getRealImage: function(a) {
console.log("----" + a + this.tagName)
},
aaa: "xxx",
click: function(e) {
console.log("-------------")
console.log(this)
Expand All @@ -21,30 +18,21 @@
console.log(e.type)
}
})
model.$watch("aaa", function(a) {
console.log(a)
})

window.onload = function() {
var elem = document.querySelector("#son")
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.target.id + "=======");
});
});

observer.observe(document.body, {
subtree: true,
childList: true
});
elem.addEventListener("DOMNodeRemovedFromDocument", function(e) {
console.log(e)


})
setTimeout(function() {
var el = document.querySelector("#parent")
el.parentNode.removeChild(el)
elem.value = "dddddddddddddddd"
}, 3000)
setTimeout(function() {
var el = document.querySelector("#parent")
el.parentNode.removeChild(el)

}, 1000)
}, 5000)

}

Expand All @@ -59,7 +47,7 @@
</style>
<div ms-controller="test">
<div id="parent">
<input id="son" />ddd
<input id="son" ms-duplex="aaa"/>ddd
</div>

<label for="female" ms-click="click">Female</label>
Expand Down

0 comments on commit a54ab14

Please sign in to comment.