Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clear interval on unbind() in apf.xmldb

  • Loading branch information...
commit 10179a17662c221c72bb010bd7e4feda485d2b34 1 parent b3fa50e
@mikedeboer mikedeboer authored
Showing with 94 additions and 79 deletions.
  1. +64 −54 apf-o3.js
  2. +30 −25 core/lib/xmldb.js
View
118 apf-o3.js
@@ -21,7 +21,7 @@
//#ifdef __SUPPORT_O3
-/**
+/**
* Ajax.org Platform for O3
*
* @author Ruben Daniels ruben@javeline.com
@@ -35,7 +35,7 @@ apf = {
TIMEOUT : 2,
ERROR : 3,
OFFLINE : 4,
-
+
//#ifdef __DEBUG
debug : true,
debugType : "Memory",
@@ -43,7 +43,7 @@ apf = {
/* #else
debug : false,
#endif */
-
+
initialized : false,
crypto : {}, //namespace
_GET : {},
@@ -68,7 +68,7 @@ apf = {
xforms : "http://www.w3.org/2002/xforms",
ev : "http://www.w3.org/2001/xml-events"
},
-
+
start : function(strAml){
this.host = null;
this.hostPath = null;
@@ -82,25 +82,25 @@ apf = {
//if (strAml)
apf.window.init(strAml || "<a:application xmlns:a='http://ajax.org/2005/aml' />");
},
-
+
importClass : function(ref, strip, win){
if (!ref)
- throw new Error(apf.formatErrorString(1018, null,
- "importing class",
+ throw new Error(apf.formatErrorString(1018, null,
+ "importing class",
"Could not load reference. Reference is null"));
-
+
if (!strip)
return apf.jsexec(ref.toString());
-
+
var q = ref.toString().replace(/^\s*function\s*\w*\s*\([^\)]*\)\s*\{/, "");
q = q.replace(/\}\s*$/, "");
-
+
//var q = ref.toString().split("\n");q.shift();q.pop();
//if(!win.execScript) q.shift();q.pop();
-
+
return apf.jsexec(q);
},
-
+
/**
* This method returns a string representation of the object
* @return {String} Returns a string representing the object.
@@ -109,12 +109,12 @@ apf = {
toString : function(){
return "[Ajax.org Platform (apf)]";
},
-
+
all : [],
-
+
/**
* This method implements all traits of another class to this object
- * @param {Function} classRef Required Class reference
+ * @param {Function} classRef Required Class reference
* @method
*/
implement : function(classRef){
@@ -122,19 +122,19 @@ apf = {
arg = arguments[i]
//#ifdef __DEBUG
if (!arg) {
- throw new Error(apf.formatErrorString(0, this,
+ throw new Error(apf.formatErrorString(0, this,
"Implementing class",
"Could not implement from '" + classRef + "'",
this.$aml));
}
//#endif
-
+
arg.call(this);//classRef
}
-
+
return this;
},
-
+
lookup : function(uniqueId){
return this.all[uniqueId];
},
@@ -173,7 +173,7 @@ apf = {
}
return dest;
},
-
+
/**
* The console outputs to the debug screen
*/
@@ -194,57 +194,57 @@ apf = {
var date = dt.getHours().toPrettyDigit() + ":"
+ dt.getMinutes().toPrettyDigit() + ":"
+ dt.getSeconds().toPrettyDigit() + "." + ms;
-
+
util.puts((nodate ? "" : date) + " " + msg + (data ? "Extra information:\n" + data : ""));
},
//#endif
-
+
debug : function(){
-
+
},
-
+
time : function(msg, subtype, data){
//#ifdef __DEBUG
this.write(msg, "time", subtype, data);
//#endif
},
-
+
log : function(msg, subtype, data){
//#ifdef __DEBUG
this.info(msg, subtype, data);
//#endif
},
-
+
info : function(msg, subtype, data){
//#ifdef __DEBUG
this.write(msg, "info", subtype, data);
//#endif
},
-
+
warn : function(msg, subtype, data){
//#ifdef __DEBUG
this.write(msg, "warn", subtype, data);
//#endif
},
-
+
error : function(msg, subtype, data){
//#ifdef __DEBUG
this.write("Error "+ "\033[35m"+msg+"\033[39m", "error",subtype,data);
//this.write("Error: " + msg + "\nStacktrace:\n" + new Error().stack, "error", subtype, data);
//#endif
},
-
+
dir : function(obj){
this.info(apf.vardump(obj, null, true));
},
-
+
teleport: function() {}
},
namespace : function(name, oNamespace){
eval("apf." + name + " = oNamespace");
},
-
+
formatErrorString : function(number, control, process, message, amlContext, outputname, output){
//#ifdef __DEBUG
var str = ["---- APF Error ----"];
@@ -254,9 +254,9 @@ apf = {
.replace(/xmlns:a="[^"]*"\s*/g, "");
}
if (control)
- str.push("Control: '"
- + (control.name
- || (control.$aml ? control.getAttribute("id") : null)
+ str.push("Control: '"
+ + (control.name
+ || (control.$aml ? control.getAttribute("id") : null)
|| "{Anonymous}")
+ "' [" + control.tagName + "]");
if (process)
@@ -277,9 +277,9 @@ apf = {
this.namespaces[namespaceURI] = oNamespace;
oNamespace.namespaceURI = namespaceURI;
},
-
+
/* Init */
-
+
/**
* Returns the directory portion of a url
* @param {String} url the url to retrieve from.
@@ -320,10 +320,10 @@ apf = {
//var fd = fs.child(sourceFile);
//eval(fd.data, self);
},
-
+
$loader : {
setGlobalDefaults : function(){
-
+
},
script : function(){
for (var i = 0; i < arguments.length; i++) {
@@ -336,28 +336,38 @@ apf = {
return this;
}
},
-
+
Init : {
add : function(func, o){
func.call(o);
},
-
+
addConditional : function(func, o, strObj){
return func.call(o);
},
-
+
run : function(strObj){
}
},
-
- destroy : function(exclude){
- //Do cleanup
+
+ unload : function(exclude){
+ var node,
+ i = 0,
+ l = this.all.length;
+ for (; i < l; i++) {
+ node = this.all[i];
+ if (node && node != exclude && node.destroy && !node.apf)
+ node.destroy(false);
+ }
+
+ if (apf.xmldb)
+ apf.xmldb.unbind(apf.window);
}
};
Function.prototype.toHTMLNode = function(highlight){
var code, line1, endLine1, line2, res;
-
+
TYPE_OBJECT = "Object";
TYPE_NUMBER = "Number";
TYPE_STRING = "String";
@@ -368,7 +378,7 @@ Function.prototype.toHTMLNode = function(highlight){
TYPE_FUNCTION = "Function";
TYPE_DOMNODE = "XMLNode";
TYPE_APFNODE = "AMLElement";
-
+
STATE_UNDEFINED = "undefined";
STATE_NULL = "null";
STATE_NAN = "NaN";
@@ -387,26 +397,26 @@ Function.prototype.toHTMLNode = function(highlight){
if (typeof variable == "number" && !isFinite(variable))
return STATE_INFINITE;
-
+
if (typeof variable == "object") {
if (variable.hasFeature)
return TYPE_APFNODE;
if (variable.tagName || variable.nodeValue)
return TYPE_DOMNODE;
}
-
+
if (typeof variable.dataType == "undefined")
return TYPE_OBJECT;
-
+
return variable.dataType;
}
-
+
//anonymous
code = this.toString();
endLine1 = code.indexOf("\n");
line1 = code.slice(0, endLine1);
line2 = code.slice(endLine1+1);
-
+
res = /^function(\s+(.*?)\s*|\s*?)\((.*)\)(.*)$/.exec(line1);
if (res) {
var name = res[1];
@@ -420,12 +430,12 @@ Function.prototype.toHTMLNode = function(highlight){
for (var i = 0; i < this.arguments.length; i++) {
//if(i != 0 && arr[i]) args += ", ";
argName = (namedArgs[i] || "NOT_NAMED").trim();// args += "<b>" + arr[i] + "</b>";
-
+
args.push("[" + getType(this.arguments[i]) + "] " + argName);
//info.push("Value: " + apf.vardump(this.arguments[i], null, false));
}
}
-
+
return " " + (name && name.trim() || "anonymous") + " (" + args.join(", ") + ")";
}
else {
@@ -438,7 +448,7 @@ $setInterval = setInterval;
apf.stacktrace = function(){
var list = [], seen = {}, loop, end;
-
+
//Opera doesnt support caller... weird...
//try {
loop = end = arguments.callee.caller.caller
View
55 core/lib/xmldb.js
@@ -37,7 +37,7 @@
*/
apf.xmldb = new (function(){
var _self = this;
-
+
this.xmlDocTag = "a_doc";
this.xmlIdTag = "a_id";
this.xmlListenTag = "a_listen";
@@ -49,7 +49,7 @@ apf.xmldb = new (function(){
var cleanRE = /(?:a_doc|a_id|a_listen|a_loaded)=(?:"|')[^'"]+(?:"|')/g,
whiteRE = />[\s\n\r\t]+</g;
-
+
/**
* Clear XML document cache periodically when no model is referencing it
*/
@@ -57,22 +57,24 @@ apf.xmldb = new (function(){
var xmlNode, cache = apf.xmldb.$xmlDocLut, docId, model;
for (var i = 0, l = cache.length; i < l; i++) {
xmlNode = cache[i];
-
+
if (!xmlNode || xmlNode.nodeFunc)
continue;
-
+
docId = i;//xmlNode.getAttribute(apf.xmldb.xmlDocTag);
model = apf.nameserver.get("model", docId);
-
+
if (!model || model.data != xmlNode) {
cache[i] = null;
}
}
- }
- if (window.setInterval)
- setInterval(function(){
- _self.garbageCollect();
- }, 60000);
+ };
+
+ this.$gcInterval = window.setInterval
+ ? setInterval(function(){
+ _self.garbageCollect();
+ }, 60000)
+ : null;
/**
* @private
@@ -270,7 +272,7 @@ apf.xmldb = new (function(){
* @private
* @todo this is cleanup hell! Listeners should be completely rearchitected
*/
-
+
// make sure that "0" is never a listener index
this.$listeners = [null];
this.addNodeListener = function(xmlNode, o, uId){
@@ -296,9 +298,9 @@ apf.xmldb = new (function(){
var model = apf.all[sUId[3]];
if (!model)
return;
-
+
if (model.$propBinds[sUId[1]][sUId[2]]) {
- if (!apf.isChildOf(model.data, xmlNode, true))
+ if (!apf.isChildOf(model.data, xmlNode, true))
return false;
var xpath = model.$propBinds[sUId[1]][sUId[2]].listen; //root
@@ -470,7 +472,7 @@ apf.xmldb = new (function(){
undoObj.name = name;
undoObj.$filled = true;
}
-
+
//Apply Changes
if (range) { //@todo apf3.0 range
undoObj.extra.range = range;
@@ -547,13 +549,13 @@ apf.xmldb = new (function(){
undoObj.oldNode = oldNode;
undoObj.xmlNode = newNode;
}
-
+
this.cleanNode(newNode);
-
+
var parentNode = oldNode.parentNode;
if (!parentNode)
return;
-
+
parentNode.replaceChild(newNode, oldNode);
this.copyConnections(oldNode, newNode);
@@ -613,10 +615,10 @@ apf.xmldb = new (function(){
apf.appendChild = function(pNode, xmlNode, beforeNode, unique, xpath, undoObj){
if (pNode == xmlNode.parentNode) //Shouldn't this be the same document?
return apf.xmldb.moveNode(pNode, xmlNode, beforeNode, null, xpath, undoObj);
-
+
if (unique && pNode.selectSingleNode(xmlNode.tagName))
return false;
-
+
// @todo: only do this once! - should store on the undo object
if (pNode.ownerDocument.importNode && pNode.ownerDocument != xmlNode.ownerDocument) {
var oldNode = xmlNode;
@@ -643,7 +645,7 @@ apf.xmldb = new (function(){
}
else if (xmlNode.parentNode)
this.removeNode(xmlNode);
-
+
if (undoObj && !undoObj.$filled) {
undoObj.$filled = true;
this.cleanNode(xmlNode);
@@ -685,7 +687,7 @@ apf.xmldb = new (function(){
//Set new id if the node change document (for safari this should be fixed)
//@todo I don't get this if...
- /*if (!apf.isWebkit
+ /*if (!apf.isWebkit
&& xmlNode.getAttribute(this.xmlIdTag)
&& apf.xmldb.getXmlDocId(xmlNode) != apf.xmldb.getXmlDocId(pNode)) {
xmlNode.removeAttribute(this.xmlIdTag));
@@ -738,7 +740,7 @@ apf.xmldb = new (function(){
var p = xmlNode.parentNode;
if (!p)
return;
-
+
p.removeChild(xmlNode);
this.applyChanges("redo-remove", xmlNode, null, p);//undoObj
@@ -757,7 +759,7 @@ apf.xmldb = new (function(){
// #ifdef __WITH_RDB
this.applyRDB(["removeNodeList", xmlNodeList, null], undoObj || {xmlNode: p});
// #endif
-
+
//if(xpath) xmlNode = xmlNode.selectSingleNode(xpath);
for (var rData = [], i = 0; i < xmlNodeList.length; i++) { //This can be optimized by looping nearer to xmlUpdate
//ActionTracker Support
@@ -917,7 +919,7 @@ apf.xmldb = new (function(){
var myQueue = notifyQueue;
notifyQueue = {};
-
+
apf.setZeroTimeout.clearTimeout(notifyTimer);
for (var uId in myQueue) {
if (!uId) continue;
@@ -939,7 +941,7 @@ apf.xmldb = new (function(){
}
}
-
+
}
/**
@@ -1100,6 +1102,9 @@ apf.xmldb = new (function(){
Nodes[i].setAttribute(this.xmlListenTag, nListen.join(";"));
}
}
+
+ if (window.clearInterval)
+ window.clearInterval(this.$gcInterval);
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.