Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Commit

Permalink
Strip the getOptionsData helper
Browse files Browse the repository at this point in the history
Since data rendering is now default in handlebars and the errors will reference data and also occur early in the dev process, the overhead both for wire size and runtime exec of this sanity check does not seem worthwhile.
  • Loading branch information
kpdecker committed Oct 14, 2014
1 parent 029494b commit 13a2bbb
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/helper-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global
ServerMarshal,
$serverSide, createError, filterAncestors, getOptionsData,
$serverSide, createError, filterAncestors,
normalizeHTMLAttributeOptions, viewHelperAttributeName
*/
var viewPlaceholderAttributeName = 'data-view-tmp',
Expand Down Expand Up @@ -55,7 +55,7 @@ Handlebars.registerViewHelper = function(name, ViewClass, callback) {
Handlebars.registerHelper(name, function() {
var args = _.toArray(arguments),
options = args.pop(),
declaringView = getOptionsData(options).view;
declaringView = options.data.view;

// Evaluate any nested parameters that we may have to content with
var expandTokens = expandHash(this, options.hash);
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/collection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global
$serverSide,
collectionElementAttributeName, createErrorMessage, getOptionsData, getParent,
collectionElementAttributeName, createErrorMessage, getParent,
helperViewPrototype, normalizeHTMLAttributeOptions,
viewRestoreAttribute
*/
Expand Down Expand Up @@ -179,7 +179,7 @@ Handlebars.registerViewHelper('collection', Thorax.CollectionHelperView, functio
});

Handlebars.registerHelper('collection-element', function(options) {
if (!getOptionsData(options).view.renderCollection) {
if (!options.data.view.renderCollection) {
throw new Error(createErrorMessage('collection-element-helper'));
}
var hash = options.hash;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/element.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*global getOptionsData, normalizeHTMLAttributeOptions */
/*global normalizeHTMLAttributeOptions */
var elementPlaceholderAttributeName = 'data-element-tmp';

Handlebars.registerHelper('element', function(element, options) {
normalizeHTMLAttributeOptions(options.hash);
var cid = _.uniqueId('element'),
declaringView = getOptionsData(options).view;
declaringView = options.data.view;
options.hash[elementPlaceholderAttributeName] = cid;
declaringView._elementsByCid || (declaringView._elementsByCid = {});
declaringView._elementsByCid[cid] = element;
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/empty.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/*global getOptionsData */
Handlebars.registerHelper('empty', function(dataObject, options) {
if (arguments.length === 1) {
options = dataObject;
}
var view = getOptionsData(options).view;
var view = options.data.view;
if (arguments.length === 1) {
dataObject = view.model;
}
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/loading.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*global getOptionsData */
Handlebars.registerHelper('loading', function(options) {
var view = getOptionsData(options).view;
var view = options.data.view;
view.off('change:load-state', onLoadStateChange, view);
view.on('change:load-state', onLoadStateChange, view);
return view._isLoading ? options.fn(this) : options.inverse(this);
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/super.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global createErrorMessage, getOptionsData */
/* global createErrorMessage */

Handlebars.registerHelper('super', function(options) {
var declaringView = getOptionsData(options).view,
var declaringView = options.data.view,
parent = declaringView.constructor && declaringView.constructor.__super__;
if (parent) {
var template = parent.template;
Expand Down
5 changes: 2 additions & 3 deletions src/helpers/template.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global getOptionsData */
Handlebars.registerHelper('template', function(name, options) {
/*jshint -W089 */
var hasHash = false;
Expand All @@ -16,10 +15,10 @@ Handlebars.registerHelper('template', function(name, options) {
context = _.extend({fn: options && options.fn}, context, options.hash);
}

var output = getOptionsData(options).view.renderTemplate(name, context);
var output = options.data.view.renderTemplate(name, context);
return new Handlebars.SafeString(output);
});

Handlebars.registerHelper('yield', function(options) {
return getOptionsData(options).yield && options.data.yield();
return options.data.yield();
});
4 changes: 2 additions & 2 deletions src/layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global
$serverSide, FruitLoops,
createErrorMessage, getLayoutViewsTargetElement, getOptionsData,
createErrorMessage, getLayoutViewsTargetElement,
normalizeHTMLAttributeOptions, viewNameAttributeName
*/
var layoutCidAttributeName = 'data-layout-cid';
Expand Down Expand Up @@ -110,7 +110,7 @@ Thorax.LayoutView.on('after-restore', function() {
});

Handlebars.registerHelper('layout-element', function(options) {
var view = getOptionsData(options).view;
var view = options.data.view;
// duck type check for LayoutView
if (!view.getView) {
throw new Error(createErrorMessage('layout-element-helper'));
Expand Down
7 changes: 0 additions & 7 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ function addEvents(target, source, context, listenToObject) {
});
}

function getOptionsData(options) {
if (!options || !options.data) {
throw new Error(createErrorMessage('handlebars-no-data'));
}
return options.data;
}

// In helpers "tagName" or "tag" may be specified, as well
// as "class" or "className". Normalize to "tagName" and
// "className" to match the property names used by Backbone
Expand Down

0 comments on commit 13a2bbb

Please sign in to comment.