REFACTOR: Remove Discourse.__widget_helpers

It's now a variable in the context where the templates are created.
This commit is contained in:
Robin Ward 2020-08-06 14:35:46 -04:00
parent 792bd3faff
commit 7df57b35da
9 changed files with 14 additions and 22 deletions

View File

@ -99,3 +99,4 @@
//= require_tree ./discourse/app/services
//= require_tree ./discourse/app/widgets
//= require ./widget-runtime

View File

@ -89,11 +89,6 @@ export function convertIconClass(icon) {
.trim();
}
// TODO: Improve how helpers are registered for vdom compliation
if (typeof Discourse !== "undefined") {
Discourse.__widget_helpers.iconNode = iconNode;
}
export function registerIconRenderer(renderer) {
_renderers.unshift(renderer);
}

View File

@ -8,7 +8,6 @@ const _pluginCallbacks = [];
const Discourse = Application.extend({
rootElement: "#main",
__widget_helpers: {},
customEvents: {
paste: "paste"

View File

@ -17,11 +17,6 @@ export function dateNode(dt) {
}
}
// TODO: Improve how helpers are registered for vdom compliation
if (typeof Discourse !== "undefined") {
Discourse.__widget_helpers.dateNode = dateNode;
}
export function numberNode(num, opts) {
opts = opts || {};
num = parseInt(num, 10);

View File

@ -64,11 +64,6 @@ export function avatarFor(wanted, attrs) {
);
}
// TODO: Improve how helpers are registered for vdom compliation
if (typeof Discourse !== "undefined") {
Discourse.__widget_helpers.avatar = avatarFor;
}
createWidget("select-post", {
tagName: "div.select-posts",

View File

@ -22,8 +22,3 @@ export default class RawHtml {
}
RawHtml.prototype.type = "Widget";
// TODO: Improve how helpers are registered for vdom compliation
if (typeof Discourse !== "undefined") {
Discourse.__widget_helpers.rawHtml = RawHtml;
}

View File

@ -0,0 +1,11 @@
// discourse-skip-module
(function(context) {
// register widget helpers for compiled `hbs`
context.__widget_helpers = {
avatar: require("discourse/widgets/post").avatarFor,
dateNode: require("discourse/helpers/node").dateNode,
iconNode: require("discourse-common/lib/icon-library").iconNode,
rawHtml: require("discourse/widgets/raw-html").default
};
})(this);

View File

@ -283,7 +283,7 @@ function compile(template) {
Object.keys(compiler.state.helpersUsed).forEach(h => {
let id = compiler.state.helpersUsed[h];
imports += `var __h${id} = Discourse.__widget_helpers.${h}; `;
imports += `var __h${id} = __widget_helpers.${h}; `;
});
return `function(attrs, state) { ${imports}var _r = [];\n${code}\nreturn _r; }`;

View File

@ -6,6 +6,7 @@ template = <<~HBS
{{actions-summary-item attrs=as}}
{{attach widget="actions-summary-item" attrs=as}}
{{testing value="hello"}}
{{date "today"}}
HBS
ctx = MiniRacer::Context.new(timeout: 15000)