Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of event code. Import build files for datasource
- Loading branch information
Justin Palmer
committed
Dec 28, 2007
1 parent
9467e1a
commit 80f725e
Showing
9 changed files
with
282 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MICROSIS.util.DataSource=Class.create({initialize:function(A,B){},}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) 2007 Justin Palmer. All Rights Reserved | ||
* Licensed under BSD license | ||
* Version 0.1.0 | ||
*/ | ||
|
||
/** | ||
* A powerful interface for accessing different types of data. | ||
* Data can come from be local such as Arrays and JSON or returned | ||
* remoteley from an XHR request. | ||
* @namespace MICROSIS.util | ||
* @requires microsis | ||
* @title Datasource Utility | ||
*/ | ||
|
||
/** | ||
* @class DataSource | ||
* @constructor | ||
* @param oLiveData {Object} Pointer to a live database | ||
* @param oConfigs {Object} (optional) Configuration hash | ||
*/ | ||
MICROSIS.util.DataSource = Class.create({ | ||
initialize: function(oLiveData, oConfigs) { | ||
|
||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<html> | ||
<head> | ||
<title>JsDoc</title> | ||
<title>Microsis</title> | ||
</head> | ||
<body> | ||
</body> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2007 Justin Palmer. All Rights Reserved | ||
* Licensed under BSD license | ||
* Version 0.1.0 | ||
*/ | ||
|
||
/** | ||
* A powerful interface for accessing different types of data. | ||
* Data can come from be local such as Arrays and JSON or returned | ||
* remoteley from an XHR request. | ||
* @namespace MICROSIS.util | ||
* @requires microsis | ||
* @title Datasource Utility | ||
*/ | ||
|
||
/** | ||
* @class DataSource | ||
* @constructor | ||
* @param oLiveData {Object} Pointer to a live database | ||
* @param oConfigs {Object} (optional) Configuration hash | ||
*/ | ||
MICROSIS.util.DataSource = Class.create({ | ||
|
||
initialize: function(oLiveData, oConfigs) { | ||
if(oConfigs && (oConfigs.constructor == Object)) { | ||
Object.extend(this, oConfigs); | ||
} | ||
|
||
if(!oLiveData) return; | ||
|
||
if(oLiveData.nodeType && oLiveData.nodeType == 9) { | ||
this.dataType = MICROSIS.util.DataSource.TYPE_XML; | ||
} else if(Object.isArray(oLiveData)) { | ||
this.dataType = MICROSIS.util.DataSource.TYPE_JSARRAY; | ||
} else if(Object.isString(oLiveData)) { | ||
this.dataType = MICROSIS.util.DataSource.TYPE_XHR; | ||
} else if(Object.isFunction(oLiveData)) { | ||
this.dataType = MICROSIS.util.DataSource.TYPE_JSFUNCTION; | ||
} else if(oliveData.nodeName && (oLiveData.nodeName.toLowerCase() == "table")) { | ||
this.dataType = MICROSIS.util.DataSource.TYPE_HTMLTABLE; | ||
} else if(Object.isObject(oLiveData)) { | ||
this.dataType = MICROSIS.util.DataSource.TYPE_JSON; | ||
} else { | ||
this.dataType = MICROSIS.util.DataSource.TYPE_UNKNOWN; | ||
} | ||
|
||
this.liveData = oLiveData; | ||
this._oQueue = {interval: null, conn: null, request: []}; | ||
|
||
// Validate and initialize public configuration | ||
var maxCacheEntries = this.maxCacheEntries; | ||
if(!Object.isNumber(maxCacheEntries) || (maxCacheEntries < 0)) | ||
maxCacheEntries = 0; | ||
|
||
// Initialize local cache | ||
if(maxCacheEntries > 0 && !this._aCache) | ||
this._aCache = []; | ||
|
||
// Initialized interval tracker | ||
this._aIntervals = []; | ||
|
||
this._sName = "DataSource instance" + MICROSIS.util.DataSource._nIndex; | ||
MICROSIS.util.DataSource._nIndex++; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/** | ||
* Copyright (c) 2007 Justin Palmer. All Rights Reserved | ||
* Licensed under BSD license | ||
* Version 0.1.0 | ||
*/ | ||
|
||
/** | ||
* The CustomEvent object allows you to create and subscribe to interesting | ||
* moments within your code. You can define events in one object and any number | ||
* of different objects can subscribe to the event, including the object the event | ||
* was created in. | ||
* | ||
* @param {String} name The name of the custom event that is passed to a subscribers | ||
* callback. | ||
* @param {Object} scope The context the custom event is invoked from. Defaults to | ||
* the window object. | ||
* @namespace MICROSIS.util | ||
* @class CustomEvent | ||
* @constructor | ||
*/ | ||
MICROSIS.util.CustomEvent = Class.create({ | ||
|
||
initialize: function(name, scope) { | ||
this.name = name; | ||
this.scope = scope || window; | ||
this.subscribers = []; | ||
this.lastError = null; | ||
}, | ||
|
||
subscribe: function(method, obj) { | ||
if(!method) { | ||
throw new Error("Invalid callback for " + this.name); | ||
} | ||
this.subscribers.push(new MICROSIS.util.Subscriber(method, obj)); | ||
}, | ||
|
||
unsubscribe: function(method, obj) { | ||
if(!method) | ||
return this.cancelSubscriptions(); | ||
var nullified = false; | ||
this.subscribers.each(function(subscriber, index) { | ||
if(subscriber && subscriber.isComposedOf(method, obj)) { | ||
this._unset(index); | ||
nullified = true; | ||
} | ||
}.bind(this)); | ||
return nullified; | ||
}, | ||
|
||
fire: function() { | ||
var length = this.subscribers.length, | ||
args = $A(arguments), | ||
ret = true, rebuild = false; | ||
|
||
if(isNaN(length)) | ||
return true; | ||
|
||
if(length == 0) | ||
rebuild = true; | ||
|
||
this.subscribers.each(function(subscriber) { | ||
try { | ||
console.log("ARGS INTERNAL", args); | ||
ret = subscriber.method.call(this.scope, args.first(), subscriber.obj); | ||
} catch(e) { | ||
this.lastError = e; | ||
} | ||
|
||
if(ret === false) | ||
return false; | ||
|
||
}.bind(this)); | ||
|
||
if(rebuild) this.subscribers = this.subscribers.compact(); | ||
|
||
return true | ||
}, | ||
|
||
_unset: function(index) { | ||
var sub = this.subscribers[index]; | ||
if(sub) { | ||
delete sub.method; | ||
delete sub.obj; | ||
} | ||
this.subscribers[index] = null; | ||
} | ||
|
||
}); | ||
|
||
MICROSIS.util.Subscriber = Class.create({ | ||
initialize: function(method, obj) { | ||
this.method = method; | ||
this.obj = obj; | ||
}, | ||
|
||
isComposedOf: function(method, obj) { | ||
if(obj) return (this.method == method && this.obj == obj); | ||
else return (this.method == method); | ||
} | ||
}); | ||
|
||
MICROSIS.util.EventProvider = { | ||
__events: null, | ||
__subscribers: null, | ||
|
||
subscribe: function(name, method, obj) { | ||
this.__events = this.__events || {}; | ||
var customEvent = this.__events[name]; | ||
|
||
if(customEvent) { | ||
customEvent.subscribe(method, obj); | ||
} else { | ||
var subscribers = this.__subscribers = this.__subscribers || {}; | ||
if(!subscribers[name]) | ||
subscribers[name] = []; | ||
|
||
subscribers[name].push({ | ||
method: method, | ||
obj: obj | ||
}); | ||
} | ||
}, | ||
|
||
unsubscribe: function(name, method, obj) { | ||
this.__events = this.__events || {}; | ||
var events = this.__events; | ||
if(name) { | ||
var customEvent = events[name]; | ||
if(customEvent) { | ||
return customEvent.unsubscribe(method, obj); | ||
} | ||
} else { | ||
var ret = true; | ||
var hasOwnProp = !!Object.prototype.hasOwnProperty, yes = null; | ||
for(var prop in events) { | ||
if(hasOwnProp) { | ||
yes = events.hasOwnProperty(prop); | ||
} else { | ||
yes = !Object.isUndefined(events[prop]) && | ||
events.constructor.prototype[prop] !== events[prop]; | ||
} | ||
|
||
if(yes) { | ||
ret = ret && events[prop].unsubscribe(method, obj); | ||
} | ||
} | ||
return ret; | ||
} | ||
return false; | ||
}, | ||
|
||
cancelSubscriptions: function(name) { | ||
return this.unsubscribe(name); | ||
}, | ||
|
||
createEvent: function(name, options) { | ||
var events = this.__events = this.__events || {}; | ||
var subscribers = this.__subscribers = this.__subscribers || {}; | ||
var opts = options || {}; | ||
|
||
if(Object.isUndefined(events[name])) { | ||
var scope = opts.scope || this; | ||
var customEvent = new MICROSIS.util.CustomEvent(name, scope); | ||
events[name] = customEvent; | ||
var sub = subscribers[name]; | ||
if(sub) { | ||
sub.each(function(subscriber) { | ||
customEvent.subscribe(subscriber.method, subscriber.obj); | ||
}); | ||
} | ||
} | ||
return events[name]; | ||
}, | ||
|
||
fireEvent: function(name) { | ||
var args = $A(arguments); | ||
var events = this.__events = this.__events || {}; | ||
var customEvent = events[name]; | ||
if(!customEvent) return null; | ||
|
||
return customEvent.fire.apply(customEvent, args); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters