-
Notifications
You must be signed in to change notification settings - Fork 6
GPII-3698 Work in progress #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d03b986
24fe982
525b868
c7dbc0e
a07eab2
0ea4e1f
43944d2
1efa27b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ | |
|
||
// A "server aware" grade that depends on being able to communicate with an instance of | ||
// `gpii.handlebars.inlineTemplateBundlingMiddleware`. | ||
|
||
fluid.defaults("gpii.handlebars.renderer.serverAware", { | ||
gradeNames: ["gpii.handlebars.renderer"], | ||
templateUrl: "/hbs", | ||
|
@@ -97,7 +98,13 @@ | |
} | ||
}, | ||
events: { | ||
"onTemplatesLoaded": null | ||
"onTemplatesLoaded": null, | ||
"onAllResourcesLoaded": { | ||
events: { | ||
// onMessagesLoaded: "onMessagesLoaded", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to explain why you commented There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit baffling, you still have the rollup event, and you still launch the template retrieval, but you've commented out the templatesLoaded event twice? |
||
onTemplatesLoaded: "onTemplatesLoaded" | ||
} | ||
} | ||
}, | ||
listeners: { | ||
"onCreate.loadTemplates": { | ||
|
@@ -128,7 +135,7 @@ | |
}; | ||
|
||
fluid.defaults("gpii.handlebars.renderer.serverMessageAware", { | ||
gradeNames: ["gpii.handlebars.renderer.serverAware"], | ||
gradeNames: ["gpii.handlebars.renderer.serverAware", "fluid.modelComponent"], | ||
messageUrl: "/messages", | ||
invokers: { | ||
"cacheMessages": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ | |
type: "gpii.handlebars.renderer.serverAware", | ||
options: { | ||
listeners: { | ||
"onTemplatesLoaded.renderMarkup": { | ||
"onAllResourcesLoaded.renderMarkup": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the rollup is a good improvement and will help once we figure out what's going on with template loading. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify, I mean that if we choose to support an event-based approach, a rollup is an improvement. |
||
func: "{gpii.handlebars.templateAware.serverAware}.renderInitialMarkup" | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,14 @@ | |
gradeNames: ["fluid.component"], | ||
components: { | ||
renderer: { | ||
type: "gpii.handlebars.renderer.serverAware" | ||
// TODO sgithens This needs to be updated depending on the app from serverAware to | ||
// serverMessageAware dynamically. | ||
type: "gpii.handlebars.renderer.serverMessageAware" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could argue that we could put comments next to any type when there are variants, but that puts the burden on implementers to know which code to read and to read it. If this switch is required often enough, maybe a mix-in grade that does this would help? i.e. a templateManager.serverMessageAware grade that is also mentioned in the docs and used in tests? |
||
}, | ||
// All components that require a renderer should be added as children of the `requireRenderer` component | ||
// to ensure that they are created once the renderer is available. | ||
requireRenderer: { | ||
createOnEvent: "{renderer}.events.onTemplatesLoaded", | ||
createOnEvent: "{renderer}.events.onAllResourcesLoaded", | ||
type: "fluid.component" | ||
} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,19 +12,25 @@ var gpii = fluid.registerNamespace("gpii"); | |
|
||
fluid.registerNamespace("gpii.handlebars.helper.messageHelper"); | ||
|
||
gpii.handlebars.helper.messageHelper.getHelper = function () { | ||
gpii.handlebars.helper.messageHelper.getHelper = function (that, serverAware) { | ||
return function (messageKey, dataOrRootContext, rootContext) { | ||
if (arguments.length < 2) { | ||
fluid.fail("You must call the 'messageHelper' helper with at least a message key."); | ||
} | ||
else { | ||
// Pick up the message bundles from the root context, which is always the last argument. | ||
var messages = fluid.get(rootContext || dataOrRootContext, "data.root.messages"); | ||
|
||
var messages; | ||
if (serverAware) { | ||
sgithens marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have another meeting with @amb26 during our overlap, this is getting a bit out of hand and it's largely my fault. I started this "server aware" pattern long ago, and it seems wrong headed for the long term. I think we'd be better off migrating to something like named global variables for message bundles, templates, et cetera, or at least using something standard like a resource loader. We should also at least figure out how/if we can avoid mixing events and model changes as we do currently. |
||
messages = fluid.get(serverAware, "model.messages"); | ||
} | ||
else { | ||
// Currently, the server verion of the renderer is still storing the messages in it's | ||
// options area, so if no serverAware is wired in, we'll assume this is running in node.js | ||
messages = fluid.get(rootContext || dataOrRootContext, "data.root.messages"); | ||
} | ||
// If we have a third argument, then the second argument is our "data". Otherwise, we use the root context (equivalent to passing "." as the variable). | ||
var data = rootContext ? dataOrRootContext : fluid.get(dataOrRootContext, "data.root"); | ||
// TODO var data = rootContext ? dataOrRootContext : fluid.get(dataOrRootContext, "data.root"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, this is another case where you've neutered a feature without any comment on why, and left the old functionality commented out. What's your thinking here? |
||
var resolver = fluid.messageResolver({ messageBase: messages }); | ||
return resolver.resolve(messageKey, data); | ||
return resolver.resolve(messageKey, {}); | ||
} | ||
}; | ||
}; | ||
|
@@ -35,7 +41,7 @@ fluid.defaults("gpii.handlebars.helper.messageHelper", { | |
invokers: { | ||
"getHelper": { | ||
"funcName": "gpii.handlebars.helper.messageHelper.getHelper", | ||
"args": ["{that}"] | ||
"args": ["{that}", "{gpii.handlebars.renderer.serverAware}"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do end up needing both "server aware" and "non server aware" in the short term, I'm wondering if we can automatically handle this using context awareness so that people only need to use the single grade. |
||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,8 @@ var Handlebars = Handlebars || {}; | |
defaultLocale: "en_us", | ||
defaultLayout: "main", | ||
events: { | ||
onTemplatesLoaded: null | ||
onTemplatesLoaded: null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should discuss whether there should be an |
||
onAllResourcesLoaded: null | ||
}, | ||
model: { | ||
messages: {}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to use async activities to populate templates and messages, one option would be to have a promise chained event that handles the loading and which fires
onAllResourcesLoaded
as its last step.