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
Make window.kolibri
object available to Hashi iframe context
#7942
Make window.kolibri
object available to Hashi iframe context
#7942
Conversation
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.
All the basics seem to be in place. One thing I would strongly urge you to consider sooner rather than later is getting some automated tests in place - the existing hashi tests should give some guidance on how to best go about that.
packages/hashi/src/mainClient.js
Outdated
} else if (options.parent) { | ||
getParams.parent = options.parent; | ||
} | ||
options.ids ? (getParams.ids = options.ids) : null; |
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.
It's purely personal preference, but I find this in-line ternary operator to conditionalize assignment a bit hard to read.
You could also achieve the effect you want here by using the lodash helper function pick
https://lodash.com/docs/4.17.15#pick
const getParams = pick(options, ['ids' ,'page', 'pageSize', 'parent']);
if (getParams.parent === 'self') {
...
}
Pick will only assign defined properties.
packages/hashi/src/mainClient.js
Outdated
|
||
// if filtering by optional params | ||
if (message.options) { | ||
let getParams = {}; |
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.
Can use const
for both getParams
and options
here as you are never reassigning their values. You've assigned it to an object, and even though you are changing the attributes of that object, you are not changing the referent of the variable.
packages/hashi/src/mainClient.js
Outdated
} | ||
|
||
__getOrUpdateContext(message) { | ||
// to update context with the incoming context |
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.
Note we need to do the URI encoding and decoding of the context here.
@@ -50,6 +52,37 @@ class Mediator { | |||
this.remote.postMessage(message, '*'); | |||
} | |||
|
|||
// a function to manage messages for kolibri.js, | |||
// when most messages require a response, to minimize redundancy | |||
sendMessageAwaitReply({ event, data, nameSpace }) { |
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.
This looks very familiar....
return new Promise((resolve, reject) => { | ||
const msgId = uuidv4(); | ||
function handler(message) { | ||
if (message.message_id === msgId && message.type === 'response') { |
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.
Once we've received the corresponding message, would be good to unregister the message handler for cleanup.
packages/hashi/src/mainClient.js
Outdated
@@ -59,6 +63,18 @@ export default class MainClient { | |||
}); | |||
}); | |||
this.mediator.sendMessage({ nameSpace, event: events.READYCHECK, data: true }); | |||
|
|||
this.on(this.events.DATAREQUESTED, message => { | |||
this.__fetchContentData(message); |
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.
I am surprised you have not needed to call .bind
on any of the handlers you have here.
…and begin refactoring mainClient
…date getParams in filtering functions
55ba11f
to
549a610
Compare
549a610
to
3d3b06b
Compare
…ough dependency injection
…s an empty object
b93ba75
to
1afd9dc
Compare
window.kolibri
object available to Hashi iframe context
This is very much a draft/WIP PR that is working to establish the foundation for a kolibri object and the core MVP functions.
Some functions are fully working, some are WIP with elements of pseudo code, as I need a more well-thought-out strategy for doing manual QA in some places. The new data-fetching code in
mainClient.js
should most likely be relocated to another file - maybe ahandlers.js
, or within the custom channels vue file which is not yet finished (TBD).I am also not sure if
__navigateTo()
is doing enough, and if it's not, what exactly needs to be adjusted/added.