Skip to content
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

GPII-3698 Work in progress #28

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sgithens
Copy link
Contributor

@sgithens sgithens commented May 9, 2019

@the-t-in-rtf This is my WIP of what has been needed to fixup the messageHelper for use in both the server and client side in a full gpii-handlebars based project (gpii-devpmt)

  • Moved the client side to read bundles from the model. I think we mentioned this should likely happen for the node.js side as well.
  • There is an issue with the best way to configure the templateManager to use the correct aware grade.
  • It's a little wonky how the grade inheritance works with deciding when to render... I changed things on the client so that the rendering always happens when a new common event allResourcesLoaded is finished. If there are any more future grades that need to read another type of resource (templates, bundles, datafiles... ) before rendering, I think they should all have them wait on firing this common event for all future grades.

"onTemplatesLoaded": null,
"onAllResourcesLoaded": {
events: {
// onMessagesLoaded: "onMessagesLoaded",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to explain why you commented onMessagesLoaded out. If there' s a new mechanism that ensures that rendering can take place after messages are loaded, fine, then it should be removed. If it's here for some other reason, you need a TODO or comment.

"onTemplatesLoaded": null,
"onAllResourcesLoaded": {
events: {
// onMessagesLoaded: "onMessagesLoaded",
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

@@ -130,7 +130,7 @@
type: "gpii.handlebars.renderer.serverAware",
options: {
listeners: {
"onTemplatesLoaded.renderMarkup": {
"onAllResourcesLoaded.renderMarkup": {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

var messages = fluid.get(rootContext || dataOrRootContext, "data.root.messages");

var messages;
if (serverAware) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

// 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");
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

@@ -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}"]
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

@@ -121,7 +121,8 @@ var Handlebars = Handlebars || {};
defaultLocale: "en_us",
defaultLayout: "main",
events: {
onTemplatesLoaded: null
onTemplatesLoaded: null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should discuss whether there should be an onMessagesLoaded event here as well, however we agree to handle things, the approach should be reflected in the common grade as well.

@@ -97,7 +98,13 @@
}
},
events: {
"onTemplatesLoaded": null
"onTemplatesLoaded": null,
"onAllResourcesLoaded": {
Copy link
Collaborator

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.

@the-t-in-rtf
Copy link
Collaborator

@sgithens and @amb26, I think I'm starting to understand the intent behind this pull, but I think we should meet to discuss whys and hows a bit.

While we wait, it would be good to at least have an approach that actually passes the associated tests. In its current state, the commented out passing of data to the message helper breaks three tests.

@the-t-in-rtf
Copy link
Collaborator

See GPII-3698 for details.

@gpii-bot
Copy link

@the-t-in-rtf
Copy link
Collaborator

@sgithens, I have been working to fix the CI config for this project. If you merge with master and commit, you should have everything you need to run tests against your work.

@jobara jobara changed the base branch from master to main October 22, 2020 17:20
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants