...
 
Commits (4)
/* /*
* KSS-RPC v0.22-beta * KSS-RPC v0.23-beta
* *
* Copyright (c) 2017, joonis new media * Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de> * Author: Thimo Kraemer <thimo.kraemer@joonis.de>
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
******************************************************************************************/ ******************************************************************************************/
var kss = { var kss = {
version: '0.22-beta', version: '0.23-beta',
_initialized: false, _initialized: false,
_ruleSheets: {}, _ruleSheets: {},
_nodeRegister: {}, _nodeRegister: {},
...@@ -238,39 +238,40 @@ kss._observe = function(records, observer) { ...@@ -238,39 +238,40 @@ kss._observe = function(records, observer) {
kss._cleanNode = function(node, deep) { kss._cleanNode = function(node, deep) {
var count = 0; var count = 0;
if (deep) {
count += kss._cleanChildNodes(node);
}
node.removeAttribute('data-has-kss'); node.removeAttribute('data-has-kss');
var kssId = node._kssId; var kssId = node._kssId;
if (!kssId) if (kssId) {
return count; kss.each(node._kssEvtHandlers, function(hnd) {
kss.each(node._kssEvtHandlers, function(hnd) { node.removeEventListener(hnd.eventname, hnd);
node.removeEventListener(hnd.eventname, hnd); hnd.node = null;
hnd.node = null; });
}); kss.each(node._kssEvtBinders, function(bnd) {
kss.each(node._kssEvtBinders, function(bnd) { if (bnd.destroy) {
if (bnd.destroy) { try { bnd.destroy(); }
try { bnd.destroy(); } catch (err) { kss.error(err); }
catch (err) { kss.error(err); } }
} });
}); delete node._kssEvtHandlers;
delete node._kssEvtHandlers; delete node._kssEvtBinders;
delete node._kssEvtBinders; delete node._kssRules;
delete node._kssRules; delete node._kssId;
delete node._kssId; delete kss._nodeRegister[kssId];
delete kss._nodeRegister[kssId]; count = 1;
count++; }
deep && kss.log('Cleand up ' + count + ' node(s)'); if (deep) {
count = kss._cleanChildNodes(node, count);
}
return count; return count;
}; };
kss._cleanChildNodes = function(node) { kss._cleanChildNodes = function(node, _count) {
_count = _count || 0;
var nodes = kss.cssQuery('*[data-has-kss]', node); var nodes = kss.cssQuery('*[data-has-kss]', node);
kss.each(nodes, function(node) { kss.each(nodes, function(node) {
kss._cleanNode(node); _count += kss._cleanNode(node);
}); });
return nodes.length; _count && kss.log('Cleaned up ' + _count + ' node(s)');
return _count;
}; };
kss._cleanUp = function(purgeAll) { kss._cleanUp = function(purgeAll) {
...@@ -282,7 +283,7 @@ kss._cleanUp = function(purgeAll) { ...@@ -282,7 +283,7 @@ kss._cleanUp = function(purgeAll) {
count++; count++;
} }
}); });
count && kss.log('Cleand up ' + count + ' node(s)'); count && kss.log('Cleaned up ' + count + ' node(s)');
}; };
kss._register = function(name, func, what, many) { kss._register = function(name, func, what, many) {
...@@ -722,7 +723,7 @@ kss._EventHandler = function(node, eventname, rule, initial) { ...@@ -722,7 +723,7 @@ kss._EventHandler = function(node, eventname, rule, initial) {
kss.each(kss._eventBinders[eventname], function(binder) { kss.each(kss._eventBinders[eventname], function(binder) {
try { try {
var bnd = new binder(this); var bnd = new binder(this);
node._kssEvtBinders.push(bnd); bnd && node._kssEvtBinders.push(bnd);
} }
catch (err) { catch (err) {
this.error(err); this.error(err);
...@@ -2728,12 +2729,6 @@ kss._TimeoutEventBinder = function(handler) { ...@@ -2728,12 +2729,6 @@ kss._TimeoutEventBinder = function(handler) {
delay: null, delay: null,
repeat: true repeat: true
}); });
this.hasServerActions = kss.each(handler.rule.actions,
function(action) {
if (action.type == 'server') {
return true;
}
}) || false;
this.setTimeout(); this.setTimeout();
}; };
...@@ -2746,16 +2741,12 @@ kss._TimeoutEventBinder.prototype = { ...@@ -2746,16 +2741,12 @@ kss._TimeoutEventBinder.prototype = {
+ 'timeout-delay: "' + delay + '"'); + 'timeout-delay: "' + delay + '"');
return; return;
} }
if (this.hasServerActions && delay < 1000) {
this.eventHandler.warn('Delay of timeout event must be '
+ 'at least 1000 for rules containing server actions');
delay = 1000;
}
var self = this; var self = this;
setTimeout(function() {self.timeout();}, delay); this.timer = setTimeout(function() {self.timeout();}, delay);
}, },
timeout: function() { timeout: function() {
this.timer = null;
var node = this.eventHandler.node; var node = this.eventHandler.node;
if (!document.documentElement.contains(node)) { if (!document.documentElement.contains(node)) {
return; return;
...@@ -2764,6 +2755,11 @@ kss._TimeoutEventBinder.prototype = { ...@@ -2764,6 +2755,11 @@ kss._TimeoutEventBinder.prototype = {
if (this.props('repeat')) { if (this.props('repeat')) {
this.setTimeout(); this.setTimeout();
} }
},
destroy: function() {
this.timer && clearTimeout(this.timer);
this.timer = null;
} }
}; };
......
This diff is collapsed.