mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Minimize use of stream
calls
This commit is contained in:
parent
8be2cb061e
commit
bdc075b266
4 changed files with 17 additions and 30 deletions
|
@ -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));
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue