Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

various resource delivery updates

  • Loading branch information...
commit 2026d12d6befbecf8cc1faf06f4a12bec0f62475 1 parent f6a4ecc
@khrome khrome authored
Showing with 32 additions and 23 deletions.
  1. +1 −1  package.json
  2. +31 −22 protolus-resource.js
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "protolus-resource",
"homepage": "https://github.com/Protolus/protolus-resource",
- "version": "0.0.3-alpha",
+ "version": "0.0.4-alpha",
"main": "protolus-resource.js",
"description": "a CommonJS based server-side resource delivery mechanism with client side shim",
"keywords": [
View
53 protolus-resource.js
@@ -92,15 +92,15 @@ var Resource = new Class({
this.removeJob();
if(this.options.onLoad) this.options.onLoad(this);
}else{
- if(!this.manifest.autogenerated){
+ //if(!this.manifest.autogenerated){
require.scan.full(this.manifest, fn.bind(function(data){
this.removeJob();
if(this.options.onLoad) this.options.onLoad(this);
}, this));
- }else{
+ /*}else{
this.removeJob();
if(this.options.onLoad) this.options.onLoad(this);
- }
+ }*/
}
this.registry.register(this.options.name, this);
},
@@ -121,7 +121,7 @@ var Resource = new Class({
this.whenReady(fn.bind(function(){
var resources = this.manifest.resources || [];
var files = resources.slice(0);
- if(fileType) dependencies = array.filter(files, Filters.fileTypeCaselessLower(fileType));
+ if(fileType && fileType != 'main') files = array.filter(files, Filters.fileTypeCaselessLower(fileType));
callback(files);
}, this));
},
@@ -186,17 +186,17 @@ Resource.Handler = new Class({
});
Resource.import = function(name, registry, callback, isDependency){
- //console.log('imp', arguments, (new Error()).stack);
if(type(registry) == 'function' && !callback){
callback = registry;
delete registry;
}
if(!registry) registry = Resource.registry;
- if(registry.explicit && !isDependency) registry.explicit.push(name)
var resource;
var handleDependencies = function(dependencies, callback){
+ if(dependencies.length === 0) callback();
array.forAllEmissions(dependencies, function(name, index, rtrn){
- Resource.import(name, registry, function(resource){
+ if(registry.require(name)) rtrn();
+ else Resource.import(name, registry, function(resource){
rtrn();
}, true);
}, function(){
@@ -204,16 +204,20 @@ Resource.import = function(name, registry, callback, isDependency){
});
};
if(!(resource = registry.require(name))){
- //if(!callback) console.log((new Error()).stack)
- new Resource(name, function(resource){
- if(!registry.require(name)){
- registry.register(name, resource);
- if(resource.dependencies) handleDependencies(resource.dependencies, function(){
- callback(resource);
- });
- else if(callback) callback(resource);
- }else if(callback) callback(registry.require(name));
- })
+ new Resource({
+ name:name,
+ registry:registry,
+ onLoad:function(resource){
+ if(!registry.require(name)){
+ if(registry.explicit && !isDependency) registry.explicit.push(name);
+ registry.register(name, resource);
+ if(resource.manifest.merged_dependencies) handleDependencies(prime.keys(resource.manifest.merged_dependencies), function(){
+ if(callback) callback(resource);
+ });
+ else if(callback) callback(resource);
+ }else if(callback) callback(registry.require(name));
+ }
+ });
}else{
if(resource.dependencies) handleDependencies(resource.dependencies, function(){
if(callback) callback(resource);
@@ -229,7 +233,7 @@ var handleExcludes = function(work, registry, excludes, callback){
callback = excludes;
excludes = [];
}
- if(!registry) registry = Resource.registry;
+ if(!registry) registry = new Resource.Registry();
if(!excludes) excludes = [];
var results = work(registry);
var filtered = [];
@@ -296,9 +300,9 @@ Resource.head = function(options, callback){ //get head
};
var results;
if(options.dependencies === false && options.explicitDependencies){
- results = Resource.explicit(options.registry, (options.excludes || []), handler);
- }else{
results = Resource.includes(options.registry, (options.excludes || []), handler);
+ }else{
+ results = Resource.explicit(options.registry, (options.excludes || []), handler);
}
}
@@ -332,6 +336,7 @@ Resource.handle = function(request, response, passthru){
'Protolus.register = '+(Client.register.toString())+';',
'window.onload = Protolus;'
].join("\n"));
+ wasResourceRequest = true;
}
if(uri.pathname.indexOf('/main/') === 0){ //commonJS modules need a wrapper
handlePath(uri.pathname, resources, options);
@@ -344,6 +349,7 @@ Resource.handle = function(request, response, passthru){
}, function(){
var results = {};
var resourceList = (options.dependencies ? registry.resources : registry.explicit);
+ //var resourceList = (registry.explicit);
array.forEachEmission(resourceList, function(resourceName, index, rtrn){
var resource = registry.require(resourceName);
var path = resource.manifest.base_directory+'/'+resource.manifest.name+'/'+resource.manifest.main;
@@ -368,19 +374,22 @@ Resource.handle = function(request, response, passthru){
else for(var key in Resource.handlers){
if(wasResourceRequest) return;
if(uri.pathname.indexOf('/'+key+'/') === 0){
+ var type = key;
handlePath(uri.pathname, resources, options);
var handler = Resource.handlers[key];
var registry = new Resource.Registry();
array.forEachEmission(resources, function(name, index, rtrn){
- Resource.import(name, registry, function(resource){
+ if(registry.require(name)) rtrn();
+ else Resource.import(name, registry, function(resource){
rtrn();
});
}, function(){
var results = [];
var resourceList = (options.dependencies ? registry.resources : registry.explicit);
+ //var resourceList = (registry.explicit);
array.forEachEmission(resourceList, function(resourceName, index, rtrn){
var resource = registry.require(resourceName);
- resource.files(key, function(files, fileNames){
+ resource.files(type, function(files, fileNames){
array.forEach(files, function(file, index){
handler.handle({
body : file,
Please sign in to comment.
Something went wrong with that request. Please try again.