Skip to content

Conversation

@juji
Copy link

@juji juji commented Aug 15, 2018

My reviews are mostly about promise, and the use of async.

Other than that:

  • prevent the script from running when window doesn't exists
  • prevent using window.cmp
  • use a param in tagManagerModule

@juji juji requested a review from ydennisy August 15, 2018 18:51
}

// will be usefull when all data are retrieved async
async _initialize(){
Copy link
Member

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?

Copy link
Author

@juji juji Aug 16, 2018

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() {
Copy link
Member

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?

Copy link
Author

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) {

Copy link
Member

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?

Copy link
Author

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
Copy link
Member

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?

Copy link
Author

@juji juji Aug 16, 2018

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;
Copy link
Member

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?

Copy link
Author

@juji juji Aug 16, 2018

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;
Copy link
Member

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?

Copy link
Author

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);
Copy link
Member

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?

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.

3 participants