-
Notifications
You must be signed in to change notification settings - Fork 0
tri review #68
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: staging
Are you sure you want to change the base?
tri review #68
Conversation
| } | ||
|
|
||
| // will be usefull when all data are retrieved async | ||
| async _initialize(){ |
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 you explain why this will be useful?
What is difference between the constructor and the initialise function?
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.
In the future, all data may be retrieved asynchronously. Just setting things up.
| } | ||
|
|
||
| showConsentTool() { | ||
| async showConsentTool() { |
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 you please explain the changes here?
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.
the async is not really important, i just forgot to delete this change.
The real changes are the ones below this line.
|
|
||
| export default function initCmp(loaderData) { | ||
| export default async function initCmp(loaderData) { | ||
|
|
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.
Again please can you explain the benefits of the suggested approach?
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.
Better readability. Assuming we know how async/await works
| const isCookiePresent = (typeof cookie === 'string'); | ||
| console.log('[INFO][Module-isShowUi]: ', !isCookiePresent); | ||
| return Promise.resolve(!isCookiePresent); | ||
| // make it sync |
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 make it sync, it cannot be used in a promise chain right?
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.
yes.. but by nature, it is not async. so we dont have to make it return promise.
edit: actually, we can use it in promise chain. but not on the start of chain.
|
|
||
| // prevent this script from running without window object | ||
| // e.g: SSR | ||
| if(typeof window === 'undefined') return; |
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.
But we need to try init() again?
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.
yes, in the browser.
For certain library (anything with node.js + SSR), Javascript are run in the server. So if this is run in the server, there will be no ERROR saying: cannot find {property} of undefined, or something like that
| .catch(err => console.error(err)); | ||
|
|
||
| await initApi(cmp); | ||
| const result = isShowUi(loaderData.iabCookie) ? await cmp.showConsentTool() : true; |
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 feels less readable, can you explain the benefit?
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 just like one-liner.
| const result = isShowUi(loaderData.iabCookie) ? await cmp.showConsentTool() : true; | ||
|
|
||
| // why do we need window.__cpm ? | ||
| cmp.readyCmpAPI(result); |
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 agree window is not good to attach to, but it is to stop having to import the cmp object in all files, maybe it should be created and exported elsewhere?
My reviews are mostly about promise, and the use of async.
Other than that:
windowdoesn't existswindow.cmptagManagerModule