summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/node_modules/okview/index.js28
1 files changed, 15 insertions, 13 deletions
diff --git a/app/node_modules/okview/index.js b/app/node_modules/okview/index.js
index 5f3a8c9..e9c0bfe 100644
--- a/app/node_modules/okview/index.js
+++ b/app/node_modules/okview/index.js
@@ -2,6 +2,7 @@ var assign = require('object-assign');
var pluralize = require('pluralize');
var isarray = require('lodash.isarray');
var Q = require('q');
+var OKQuery = require('okquery');
var OKResource = require('okresource');
// Routes for views over collections have a special pattern
@@ -18,11 +19,11 @@ function OKView(options) {
if (!(this instanceof OKView)) return new OKView(options);
options = options || {};
if (!options.template)
- throw new Error('No template provided to view.');
+ throw new Error('No template provided to OKView.');
if (!options.meta)
- throw new Error('No meta resource provided to view');
+ throw new Error('No meta resource provided to OKView');
if (!options.route)
- throw new Error('No route provided to view');
+ throw new Error('No route provided to OKView');
var route = options.route;
var mount = options.mount || 'get';
this._template = options.template;
@@ -32,28 +33,29 @@ function OKView(options) {
// resource will be resolved later
// TODO This bound / unbound thing can probably be expressed in a
// less convoluted way.
- var unbound = this.unbound = !!UNBOUND_ROUTE_PATTERN.exec(this.route);
+ var unbound = this.unbound = !!UNBOUND_ROUTE_PATTERN.exec(route);
+
Object.defineProperty(this, 'mount', {
value: mount,
writable: false,
enumerable: true
});
+
Object.defineProperty(this, 'route', {
value: route,
writable: false,
enumerable: true
});
+
this._middleware = createMiddleware(this);
- this._fetchTemplateData = unbound ?
- fetchResourceTemplateData : fetchCollectionTemplateData;
+ this._fetchTemplateData = unbound ? fetchUnbound : fetchBound;
- function fetchResourceTemplateData(id) {
- // Bound views only have a single query
- // TODO This is super convoluted
+ function fetchUnbound(id) {
+ // TODO Janky
return fetchTemplateData(meta, [queries[0].get(id)]);
}
- function fetchCollectionTemplateData() {
+ function fetchBound() {
return fetchTemplateData(meta, queries);
}
}
@@ -65,7 +67,7 @@ OKView.prototype.middleware = function() {
OKView.prototype.render = function(req, res, data) {
this._template.render(data).then(function(html) {
res.send(html);
- }, errorHandler(req, res, data));
+ }).fail(errorHandler(req, res, data));
};
OKView.prototype.fetchTemplateData = function() {
@@ -97,7 +99,7 @@ function unboundMiddleware(view) {
var id = req.params[paramName];
view.fetchTemplateData(id).then(function(data) {
view.render(req, res, data);
- }, errorHandler(req, res, next));
+ }).fail(errorHandler(req, res, next));
};
}
@@ -109,7 +111,7 @@ function boundMiddleware(view) {
return function(req, res, next) {
view.fetchTemplateData().then(function(data) {
view.render(req, res, data);
- }, errorHandler(req, res, next));
+ }).fail(errorHandler(req, res, next));
};
}