Permalink
Browse files

solving conflicts before the merge after the introduction of getStati…

…cAppConfig() method
  • Loading branch information...
2 parents 6c6834c + 00b1862 commit 645fd2afdf23582ccd9d6c9f75219d5116649516 @caridy committed Jan 28, 2013
@@ -351,7 +351,13 @@ YUI.add('addon-rs-config', function(Y, NAME) {
// since application.json is optional, we should be careful
// in any case there is a low-level cache mechanism going on here.
if (Y.Lang.isArray(this.readConfigSimple(rootAppJSON))) {
- ycb = this.readConfigYCB(rootAppJSON, {});
+ // ensuring the context runtime:server to read applicationConfigFiles,
+ // it does not matter if runtime is not a dimension, it works just fine
+ // since the purpose of this block is to read applicationConfigFiles
+ // from /application.json, and the rest is part of this.createMultipartYCB
+ ycb = this.readConfigYCB(rootAppJSON, {
+ runtime: 'server'
+ });
// adding the master application.json as the top level
paths.push(rootAppJSON);
// optional applicationConfigFiles to mix in more configs
@@ -308,7 +308,7 @@ YUI.add('mojito-action-context', function(Y, NAME) {
this._adapter = opts.adapter;
// pathToRoot, viewEngine, amoung others will be available through this.
- this.staticAppConfig = store.getAppConfig(store.getStaticContext());
+ this.staticAppConfig = store.getStaticAppConfig();
// Create a function which will properly delegate to the dispatcher to
// perform the actual processing.
View
@@ -0,0 +1,116 @@
+/*
+This code does not work and is only a proof of concept.
+I do not know the internals of Mojito, this is just
+my "pie-in-the-sky" thoughts of what I would like to see.
+*/
+
+//Simple Use Case
+var mojito = require('mojito');
+
+var app = mojito.createServer();
+
+/*
+This middleware can be custom or default
+Mojito behavior to augment the `req` object
+with context sensative information, example:
+
+var req = {
+ auth: 'cookie',
+ intl: 'de',
+ user: {
+ //user object with prefs
+ },
+ bucket: 'a1'
+};
+
+*/
+app.use(mojito.core);
+
+/*
+Thoughts on differences between local and prod.
+Locally, you want assets loaded locally with a smart local combo server.
+In Production, you want to use the CDN deployment that `shaker` handles.
+*/
+
+app.configure('development', function() {
+ app.use(mojito.yui('3.9.0').local);
+ app.use('/combo', mojito.middleware.combo);
+});
+app.configure('production', function() {
+ app.use(mojito.yui('3.9.0').cdn);
+ app.use(mojito.middleware.combo.cdn);
+});
+
+/*
+Simple:
+Renders this template from a named datastore
+*/
+app.get('/', mojito.dispatch('index'));
+
+/*
+Advanced:
+- `mojito.bucket` - bucket middleware to augment how dispatch works
+- `mojito.auth` & `mojito.cookie` random middleware, name not important
+- `mojito.rest` Read below
+- Render a named template from a datastore and bind it to the server
+*/
+app.get('/foo', mojito.bucket('a4'), mojito.auth, mojito.cookie, mojito.rest('baz'), mojito.dispatch('foo'));
+
+/*
+This is a little magic, the named datastore here is turned into
+a rest API, example:
+*/
+
+app.get('_mojito/baz', mojito.rest('baz').get);
+app.head('_mojito/baz', mojito.rest('baz').head);
+app.post('_mojito/baz', mojito.rest('baz').post);
+app.put('_mojito/baz', mojito.rest('baz').put);
+app.delete('_mojito/baz', mojito.rest('baz').delete);
+
+/*
+These could also resolve to something like:
+Where :guid is a unique client id (normally a cookie, but middleware
+should dictate that).
+*/
+app.put('_mojito/:guid/baz', mojito.rest('baz').put);
+
+/*
+This becomes a binder for the model on the client and on the server.
+When the binder on the client issues a Model.save() it automagically
+syncs with this datastore. When this datastore on te server is changed
+(via timed YQL call?) the results are pushed to the client Model to sync.
+
+The Model on the server can be a Y.Model or another Object with a defined
+API so that YUI is technically not required. Same for the client. The Binder
+is defined as an API that is mimicable by any Object with getters & setters.
+Ideally, this plumbing is free if you use Y.App on the client. But could
+potentially be usable by any (Backbone) MVC framework or just Vanilla JS.
+*/
+
+/*
+Super Advanced:
+*/
+
+var mojito = require('mojito'),
+ exress = require('express');
+
+var app = express.createServer();
+
+app.use('_my_mojito', mojito.middleware.bigPipe);
+app.use(express.*);
+
+
+app.get('/', express.foo, mojito.middleware.bar, mojito.middleware.baz, function(req, res) {
+ var myData = new MyDataStore({ /*...*/ });
+ var template = mojito.prepare('my-template', { /*...*/});
+ var mojit = new mojito.Mojit(req, res, template, { /*...*/ });
+ /* do something special */
+ mojit.rest.binder(myData, res, template);
+ mojit.render({ /*...*/ }, function(err, html) {
+ if (err) {
+ throw err;
+ }
+ html = doSomethingElseWithTheOutput(html);
+ mojit.send(html, 200);
+ });
+});
@@ -236,6 +236,16 @@ YUI.add('mojito-client-store', function(Y, NAME) {
/**
+ * Returns the static (non-runtime-sensitive) version of the application.json.
+ * @method getStaticAppConfig
+ * @return {object} the configuration from applications.json
+ */
+ getStaticAppConfig: function(ctx) {
+ return this.appConfig;
+ },
+
+
+ /**
* Returns the routes configured in the application.
* @method getRoutes
* @param {object} ctx the context
@@ -174,6 +174,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
this._config.dir;
this._config.mojitoRoot = this._config.mojitoRoot ||
this._libs.path.join(__dirname, '../..');
+
this._jsonCache = {}; // fullPath: contents as JSON object
this._ycbCache = {}; // fullPath: context: YCB config object
this._routesCache = {}; // serialized context: route
@@ -182,6 +183,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
this._getMojitTypeDetailsCache = {}; // env+posl+lang+mojitType: value
this._expandSpecCache = {}; // env+ctx+spec: value
+ this._packagesVisited = {}; // package@version: path
this._appRVs = []; // array of resource versions
this._mojitRVs = {}; // mojitType: array of resource versions
this._appResources = {}; // env: posl: array of resources
@@ -886,8 +888,8 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
if (res.url && res.source.fs.isFile) {
if (urls[res.url]) {
Y.log('Url collision for ' + res.url +
- '. Choosing: ' + urls[res.url].source.fs.fullPath +
- ' over ' + res.source.fs.fullPath, 'warn', NAME);
+ '. Choosing:\n' + urls[res.url].source.fs.fullPath +
+ ' over\n' + res.source.fs.fullPath, 'warn', NAME);
} else {
urls[res.url] = res;
}
@@ -1102,6 +1104,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
this.selectors = {};
this._appRVs = [];
this._mojitRVs = {};
+ this._packagesVisited = {};
walker = new this._libs.walker.BreadthFirst(this._config.root);
walker.walk(function(err, info) {
@@ -1509,12 +1512,14 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
//console.log(selectors);
//console.log(affinities);
+ // app-level
if (!this._appResources[env]) {
this._appResources[env] = {};
}
this._appResources[env][poslKey] =
this._resolveVersions(affinities, selectors, sourceBase, [ this._appRVs ]);
+ // mojit-level
if (!this._mojitResources[env]) {
this._mojitResources[env] = {};
}
@@ -1657,7 +1662,8 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
*/
_preloadPackage: function(info) {
var dir,
- pkg;
+ pkg,
+ visitKey;
// FUTURE: use info.inherit to scope mojit dependencies
/*
console.log('--PACKAGE-- ' + info.depth + ' ' + info.pkg.name + '@' + info.pkg.version
@@ -1680,6 +1686,13 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
if (!info.pkg.yahoo || !info.pkg.yahoo.mojito) {
return;
}
+ visitKey = [info.pkg.name, info.pkg.version].join('@');
+ if (this._packagesVisited[visitKey]) {
+ Y.log('skipping duplicate package ' + visitKey + '\nskipping ' +
+ info.dir + '\nprev used ' + this._packagesVisited[visitKey], 'info', NAME);
+ return;
+ }
+
switch (info.pkg.yahoo.mojito.type) {
case 'bundle':
dir = this._libs.path.join(info.dir, info.pkg.yahoo.mojito.location);
@@ -1693,6 +1706,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
Y.log('Unknown package type "' + info.pkg.yahoo.mojito.type + '"', 'warn', NAME);
break;
}
+ this._packagesVisited[visitKey] = info.dir;
},
View
@@ -275,7 +275,7 @@ MojitoServer.prototype._configureAppInstance = function(app, options) {
options.context = {};
}
- appConfig = store.getAppConfig(store.getStaticContext());
+ appConfig = store.getStaticAppConfig();
yuiConfig = (appConfig.yui && appConfig.yui.config) || {};
// redefining "combine" and/or "base" in the server side have side effects
@@ -489,18 +489,22 @@ MojitoServer.prototype.getHttpServer = function() {
* Begin listening for inbound connections.
* @param {Number} port The port number. Defaults to the server's value for
* options.port (which defaults to process.env.PORT followed by 8666).
- * @param {String} host The hostname or IP address in string form.
+ * @param {String} host Optional hostname or IP address in string form.
+ * @param {Function} callback Optional callback to get notified when the
+ * server is ready to server traffic.
*/
-MojitoServer.prototype.listen = function(port, host, cb) {
+MojitoServer.prototype.listen = function(port, host, callback) {
var logger,
app = this._app,
p = port || this._options.port,
h = host || this._options.host,
- callback = cb || Mojito.NOOP,
handler = function(err) {
- callback(err, app);
- };
+ if (callback) {
+ callback(err, app);
+ }
+ },
+ listenArgs = [p];
// Track startup time and use it to ensure we don't try to listen() twice.
if (this._startupTime) {
@@ -515,14 +519,17 @@ MojitoServer.prototype.listen = function(port, host, cb) {
libutils.warn('Starting Mojito Application');
}
+ if (h) {
+ listenArgs.push(h);
+ }
+ if (callback) {
+ listenArgs.push(handler);
+ }
+
try {
- if (h) {
- app.listen(p, h, handler);
- } else {
- app.listen(p, handler);
- }
+ app.listen.apply(app, listenArgs);
} catch (err) {
- callback(err);
+ handler(err);
}
};
@@ -1,10 +1,13 @@
[
{
- "settings": [ "master" ],
+ "settings": [ "runtime:common" ],
"applicationConfigFiles": [
"node_modules/devices/application.json",
"node_modules/runtimes/application.json"
- ],
+ ]
+ },
+ {
+ "settings": [ "master" ],
"testKey1": "testVal1",
"testKey2": "testVal2",
"testKey3": "testVal3"

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 645fd2a

Please sign in to comment.