From bdc075b266c0ade95108a7a1df0a7fe3140e8156 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 11 Dec 2014 13:33:07 -0500 Subject: [PATCH] Minimize use of `stream` calls --- .../javascripts/discourse/helpers/raw.js.es6 | 16 +++------------- .../discourse/helpers/register-unbound.js.es6 | 12 +++++++----- .../discourse/lib/ember_compat_handlebars.js | 15 +++++---------- app/assets/javascripts/main_include.js | 4 ++-- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/discourse/helpers/raw.js.es6 b/app/assets/javascripts/discourse/helpers/raw.js.es6 index b65dbd8f6..c6db3dfef 100644 --- a/app/assets/javascripts/discourse/helpers/raw.js.es6 +++ b/app/assets/javascripts/discourse/helpers/raw.js.es6 @@ -1,20 +1,10 @@ -Handlebars.registerHelper('raw', function(property, options) { - var templateName = property + ".raw", - template = Discourse.__container__.lookup('template:' + templateName), - params = options.hash; +import registerUnbound from 'discourse/helpers/register-unbound'; +registerUnbound('raw', function(templateName, params) { + var template = Discourse.__container__.lookup('template:' + templateName + '.raw'); if (!template) { Ember.warn('Could not find raw template: ' + templateName); return; } - - if (params) { - for (var prop in params) { - if (options.hashTypes[prop] === "ID") { - params[prop] = Ember.get(this, params[prop], options); - } - } - } - return new Handlebars.SafeString(template(params)); }); diff --git a/app/assets/javascripts/discourse/helpers/register-unbound.js.es6 b/app/assets/javascripts/discourse/helpers/register-unbound.js.es6 index 729c86376..2ed2c0bd9 100644 --- a/app/assets/javascripts/discourse/helpers/register-unbound.js.es6 +++ b/app/assets/javascripts/discourse/helpers/register-unbound.js.es6 @@ -1,7 +1,11 @@ -function registerUnbound(name, fn) { +var get = Discourse.EmberCompatHandlebars.get; + +export default function registerUnbound(name, fn) { Handlebars.registerHelper(name, function(property, options) { - property = Discourse.EmberCompatHandlebars.get(this, property, options); + if (options.types[0] === "ID") { + property = get(this, property, options); + } var params = {}, hash = options.hash; @@ -12,7 +16,7 @@ function registerUnbound(name, fn) { if (type === "STRING") { params[k] = hash[k]; } else if (type === "ID") { - params[k] = options.data.view.getStream(hash[k]).value(); + params[k] = get(this, hash[k], options); } }); } @@ -20,5 +24,3 @@ function registerUnbound(name, fn) { return fn(property, params); }); } - -export default registerUnbound; diff --git a/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js b/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js index 35819b3df..d1823f80e 100644 --- a/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js +++ b/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js @@ -96,17 +96,12 @@ return template; }; - RawHandlebars.get = function(_this, property, options){ - var val = property; - if (options.types[0] === "ID"){ - if (options.types && options.data.view) { - val = options.data.view.getStream(property).value(); - } else { - val = Em.get(_this, property); - } + RawHandlebars.get = function(ctx, property, options){ + if (options.types && options.data.view) { + return options.data.view.getStream(property).value(); + } else { + return Ember.get(ctx, property); } - - return val; }; Discourse.EmberCompatHandlebars = RawHandlebars; diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js index a94e7b150..8e1d9d8c3 100644 --- a/app/assets/javascripts/main_include.js +++ b/app/assets/javascripts/main_include.js @@ -1,5 +1,3 @@ -//= require ./discourse/helpers/register-unbound -//= require ./discourse/helpers/i18n_helpers //= require ./discourse/mixins/ajax //= require ./discourse @@ -13,6 +11,8 @@ // Stuff we need to load first //= require ./discourse/lib/ember_compat_handlebars +//= require ./discourse/helpers/register-unbound +//= require ./discourse/helpers/i18n_helpers //= require ./discourse/lib/computed //= require ./discourse/mixins/scrolling //= require_tree ./discourse/mixins