-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix: replace global variable and refactor code #71
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.
I've reported a few findings.
cc: @zongqichen @Fannon @swennemers
Putting two cents: enums vs objects in javascriptYou can find on many places that javascript developers prefer using Object.freeze instead of enum (or Enum can be defined as:
Please pay attention on Object.freeze. It serves to disallow changing of the object which at the end causes that RESOURCE_TYPE acts as an enum. |
I think that the code:
can be written this way:
where I think that instead of |
I create an issue regarding to this refactor: #73 |
"api": "api" | ||
}); | ||
|
||
const COMPILER_TYPES = Object.freeze( |
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 would name this constant as "CDS_COMPILE_TO" and also add the other targets: sql, hana, asyncapi, json, hana, edm, yaml and cdl. Just for the sake of completeness.
"edmx": "edmx" | ||
}); | ||
|
||
const CONTENT_MERGE_KEY = 'ordId' |
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.
const CONTENT_MERGE_KEY = 'ordId' | |
const ORD_KEY = 'ordId' |
break; | ||
case COMPILER_TYPES.asyncapi2: | ||
try { | ||
responseFile = asyncapi(csn, options); |
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 don't understand why is somewhere called imported function(like asyncapi here), and somewhere is used the whole cds.compile.to...
statement. Is there some particular reason?
const fGeneratePaths = (srv, srvDefinition) => { | ||
const srvObj = { name: srv, definition: srvDefinition }; | ||
const protocols = cds.service.protocols; | ||
const generatePaths = (srv, srvDefinition) => { |
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 is a private function, right? Maybe to name it _generatePath
?
Also, when defining functions, on some places we use function
and on the others const
. Do we follow some rule when to use what? I couldn't find any regularity, it seems it was randomly/arbitrarily decided.
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.
As #57 discussed, we should use function
}), | ||
{} | ||
); | ||
const readORDExtensions = (srv) => |
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.
We are calling this function in multiple places in a sequence when generating ord document and every time we have the same input parameter - serviceDefinition. Why not to call this function once when starting generating ORD document and then pass the result as an input parameter of all subsequent functions: _getGroups, _getApiResources, _getEventResources... ?
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.
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.
let's close this PR and fix this as part of the next PR #64
No description provided.