Skip to content

Singleton to manage requests for resources (text / JSON / images / composite and recursive).

Notifications You must be signed in to change notification settings

Craigmoore/CAMResourceManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

ResourceManager is a singleton javascript object that acts a central resource loading and caching object.

It is dependant on

1) JQuery (current version v1.4.4)
2) John Resig's JSON2.stringify() function
3) jshash-2.2 (although this is more of an aesthetic decision, I am using JSON as hashes for the cacheing keys, this can be ignored by commenting/uncommenting line 43-44).

When referring to a resource, it not necessarily known whether or not the resource has been loaded or not. By creating a request object in the format

// For basic resource types
{type : 'text' || 'JSON' || 'image' || 'image' || 'video', resourceTypeFunc : 'Object' (optional), url : '', data : {}, additional : {}, processResource : function(resource){//do stuff with resource}}

OR

// For requesting multiple simultanous resources to be used as parameters for a single overall resource object
{type : 'composite', requests : [array of requests for objects], additional : {}, resourceTypeFunc}

OR

// For requesting a followup request for instructions on how to produce a resource
{type : 'request', url : '', data : {}, additional : {}, processResource : function() { //Do stuff with resource}}


and calling ResourceManager.addRequest(), the resource(s) will be loaded or pulled from local cache and the processResource function will be called.

A basic resource request can be produced by calling ResourceManager.createRequest(iType, rTF, iUrl, iData, iPR). The "additional" parameter is entirely optional and can contain additional data from the application to be used within processResource(). It will be copied across when following up requests of type "request".

In addition, if the resourceTypeFunc has been defined, the resource(s) will be passed to the factory method contained before being cache and passed back.

The resourceTypeFunc functions can be extended by

ResourceManager.resourceProcessingFunctions.Material = function(resource, junkDiv) {
	var m = new MyArbritraryObject(resources);
	return m;
};

One additional "feature" is that if 2-3 requests are attempted to be made simultaneously, the first request will be made and the subsequent requests will be added to the "waitingForResources" list, and then the resource becomes available, all requests are fired to process the resource.

Image and script resources have been added and tested, and video still requires testing.

Caveats

1) There is no automatic adding of files to implement the resourceTypeFunc functions... these have to be generated/linked by hand.

Future development requirements :

1) Video.someEvent callbacks to make these as resource types.
2) These purely ".src" based elements will require a url : '', options : {} conversion to a single .src value
3) A parameter to either ignore the cache or force a refresh.
4) A slight adjustment to allow the reuse of resources having run through a different resourceTypeFunc method.
5) This object may require a little engineering to not pollute the global variable space etc, or to be a Jquery extension. At the moment it merely uses JQuery.

About

Singleton to manage requests for resources (text / JSON / images / composite and recursive).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published