Permalink
Browse files

added action attribute for expandInstance either on client/server and…

… tunnel
  • Loading branch information...
1 parent 242a030 commit 860decee5ee34e3b90eb577623aa8aedb9d62e43 @diervo committed Sep 19, 2012
@@ -172,6 +172,7 @@ YUI.add('mojito-mojit-proxy', function(Y, NAME) {
instance = {
base: this._base,
type: this.type,
+ action: action,
guid: this._instanceId, // DEPRECATED, use instanceId instead
instanceId: this._instanceId,
config: Y.mojito.util.copy(this.config)
@@ -61,23 +61,23 @@ YUI.add('mojito-resource-store-adapter', function(Y, NAME) {
// DEPRECATED, but kept in case a user is using.
instance.guid = instance.instanceId;
+ source.action = instance.action;
// What are being asked to expand?
if (instance.base) {
- source.name = instance.base;
+ source.base = source.name = instance.base;
source.func = this.getSpec;
} else if (instance.type) {
- source.name = instance.type;
+ source.type = source.name = instance.type;
source.func = this.getType;
} else {
// We don't have any inputs so fail
throw new Error('There was no info in the "instance" object');
}
-
// This contains the app "definition" and app config
my.getApp(env, context, function(app) {
// Here we get either the a spec or a type
- source.func(env, source.name, context, function(err, data) {
+ source.func(env, source, context, function(err, data) {
if (err) {
callback(err, {});
return;
@@ -135,9 +135,10 @@ YUI.add('mojito-client-store', function(Y, NAME) {
/*
* TODO: REVIEW RE [Issue 76].
*/
- getSpec: function(env, id, context, callback) {
+ getSpec: function(env, spec, context, callback) {
- var parts = id.split(':'),
+ var id = spec.name,
+ parts = id.split(':'),
typeName = parts[0],
specName = parts[1] || 'default',
ns = typeName.replace(/\./g, '_'),
@@ -149,8 +150,12 @@ YUI.add('mojito-client-store', function(Y, NAME) {
// just fine.
url = this.staticPrefix + '/' + typeName + '/specs/' + specName +
'.json';
+ url += '?' + Y.QueryString.stringify(context);
- url = this.buildUrl(url, context);
+ // this is mainly used by html5app
+ if (this.appConfig.pathToRoot) {
+ url = this.appConfig.pathToRoot + url;
+ }
// use the compiled version if there was one built
if (isCompiled(ns, specName)) {
@@ -162,19 +167,23 @@ YUI.add('mojito-client-store', function(Y, NAME) {
retrieveFile(url, callback);
},
-
/*
* TODO: REVIEW RE [Issue 77]
*/
- getType: function(env, type, context, callback) {
+ getType: function(env, spec, context, callback) {
// This should really have the tunnelPrefix. However, that
// complicates offline apps (from `mojito build html5app`).
// The mojito-handler-tunnel will be able to handle this URL
// just fine.
- var url = this.staticPrefix + '/' + type + '/definition.json';
+ var type = spec.name,
+ url = this.staticPrefix + '/' + type + '/definition.json';
+ url += '?' + Y.QueryString.stringify(context);
- url = this.buildUrl(url, context);
+ // this is mainly used by html5app
+ if (this.appConfig.pathToRoot) {
+ url = this.appConfig.pathToRoot + url;
+ }
retrieveFile(url, callback);
},
@@ -193,30 +202,6 @@ YUI.add('mojito-client-store', function(Y, NAME) {
*/
getRoutes: function() {
return this.routes;
- },
-
- /**
- * Checks the given URL and adds a context query string.
- * @param url {String} the relative url
- * @param context {Object} the runtime context
- * @return {String}
- */
- buildUrl: function (url, context) {
-
- if ('/' !== url.charAt(0)) {
- url = '/' + url;
- }
-
- // this is mainly used by html5app
- if (this.appConfig.pathToRoot) {
- url = this.appConfig.pathToRoot + url;
- }
-
- if (context) {
- url += '?' + Y.QueryString.stringify(context);
- }
-
- return url;
}
};
View
@@ -471,7 +471,8 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
* @param {function(err,spec)} callback callback used to return the results (or error)
*/
getSpec: function(env, id, ctx, callback) {
- this.expandInstanceForEnv(env, {base: id}, ctx, function(err, obj) {
+ var base = Y.Lang.isString(id) ? {base: id} : id;
+ this.expandInstanceForEnv(env, base, ctx, function(err, obj) {
if (err) {
callback(err);
return;
@@ -495,7 +496,8 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
* @param {function(err,spec)} callback callback used to return the results (or error)
*/
getType: function(env, type, ctx, callback) {
- this.expandInstanceForEnv(env, {type: type}, ctx, function(err, obj) {
+ var typeObj = Y.Lang.isString(type) ? {type: type} : type;
+ this.expandInstanceForEnv(env, typeObj, ctx, function(err, obj) {
if (err) {
callback(err);
return;

0 comments on commit 860dece

Please sign in to comment.